Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
#python#DataStructures#algorithms
🐍
Python Data Structures & Algorithms
What you will get in this course:
- Data Structures
Lists
Linked Lists
Doubly Linked Lists
Stacks & Queues
Binary Trees
Hash Tables
Graphs
- Algorithms
- Sorting
Bubble Sort
Selection Sort
Insertion Sort
Merge Sort
Quick Sort
- Searching
Breadth First Search
Depth First Search
🔗Link
-----
Main channel:@repo_science
Coupons:@freecoupons_reposcience
-----
#python#Algorithms#dataStructures
🐍
Hands-On Data Structures and Algorithms with Python: Store, manipulate, and access data effectively and boost the performance of your applications
🖇3rd Edition
📆2022
✍️Dr. Basant Agarwal
🔗Link
-----
Main channel: @repo_science
Coupons: @freecoupons_reposcience
-----
#DataStructures#Algorithms#Java
🛠
The Ultimate Data Structures & Algorithms Course
What You'll Learn...
This course is divided into three parts, each about 5 hours long so you can easily complete it.
The first part is all about linear data structures and their algorithms:
- Big O Notation
- Arrays
- Linked Lists
- Stacks
- Queues
- Hash Tables
The second part covers non-linear data structures and their algorithms:
- Binary Trees
- AVL Trees
- Heaps
- Tries
- Graphs
The third part explores:
- Searching Algorithms
- Sorting Algorithms
- String Manipulation Algorithms
🗣Mosh Hamedani
🔗Link
-----
Main channel:@repo_science
Coupons:@freecoupons_reposcience
-----
#DataStructures#Algorithm#designStrategies
📚
A Textbook of Data Structures and Algorithms, Volume 3: Mastering Advanced Data Structures and Algorithm Design Strategies
🔗Link
-----
Main channel: @repo_science
Coupons: @freecoupons_reposcience
-----