Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
The international community has failed people in #Gaza. Humanity has failed. But every day brings new opportunities to change course, and stop the killing. The only lesson we can take is to redouble efforts to pressure for a #ceasefireNOW
https://t.me/claredalymep/275
🔴 Gaza's smallest refugee camp pounded by Israeli airstrikes. Palestinians digging up bodies of loved ones under rubble. Over 90 killed, including children and displaced families. Entire residential blocks wiped out. Camp housing estimated 100,000 people. No warnings given. No aid, fuel, or excavators. Need ceasefire! Arab world, stand with us! #GazaUnderAttack#CeasefireNow
https://www.aljazeera.com/features/2023/12/28/piles-of-body-parts-gazas-maghazi-residents-find-families-in-pieces
Subscribe to @BadVolfNews
🚨 Urgent Call for Ceasefire in Gaza 🚨
USAID staff demand immediate end to violence, decrying civilian deaths and violations of international law. Aid efforts futile amidst indiscriminate bombing. Gaza needs more than just aid, it needs the bombs to stop. Pressure mounts on US government to take action, hold all parties accountable. UN warns of grave risk of genocide. Meanwhile, US continues unwavering support for Israel, providing billions in military aid. Will Congress break the silence? #CeasefireNow#GazaCrisis
https://www.aljazeera.com/news/2023/11/8/more-than-1000-usaid-employees-sign-letter-backing-gaza-ceasefire
Subscribe to @BadVolfNews
Protests swept over Tel Aviv as almost 300,000 people took to the streets to call for bringing back hostages, with no mention of a ceasefire.
#Gaza#Ceasefire#CeasefireNow#Palestine
A bereaved mother mourns her child, as another one of her children is brought in, killed by an Israeli airstrike.
#Gaza#Palestine#Ceasefire#CeasefireNow