Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
Some see a structure. We see a symbol.
Some see concrete. We see the collective will of 150 million people.
Some see a river diverted. We see a destiny harnessed.
The Grand Ethiopian Renaissance Dam is not just about generating megawatts; it's about generating hope. It's about empowering a nation to write its own story of prosperity. It's about telling the world that our future is in our own hands, powered by our own resources.
This is the pride of Ethiopia. A new era of light, energy, and sovereignty.
#ItsMyDam#EthiopiaRising#GERD#NationalPride#Development#Africa
http://t.me/etbisahusen
🎙️WEEK 17 | LIVE DISCUSSION
⚔🛡My Generation & Adwa
Reflecting on the 130th Anniversary of the Victory of Adwa
In honor of the 130th Anniversary of the Victory of Adwa, celebrated on Yekatit 23, 2018 (E.C.), we invite you to a powerful and timely conversation on legacy, identity, and national consciousness.
Tonight, on the Ethiopia First Telegram Channel, we will discuss, reflect, and critically engage on what Adwa means for our generation — and why it still matters today.
Be part of this historic dialogue.
📅February 27, 2026
🕗8:00–10:00 PM (EST) | 2:00–4:00 PM (Ethiopia Time)
🎙️Host: Ethiopia First
🗣️Guest: Alexander Yohannes — Red Nile Media
🔗Join Live:https://t.me/+AAE_Pc8aWTczYTA0
—
#Adwa130#VictoryOfAdwa#AdwaAnniversary#MyGenerationAndAdwa
#EthiopiaFirst#RedNileMedia#EthiopianHistory#AfricanVictory
#PanAfricanLegacy#Yekatit23#EthiopianPride#AdwaSpirit#EthiopiaRising