Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
🚨*ATTENTION*
*The British chapter of the Antifascist International* calls on the oppressed of the world to stand firmly with Venezuelan 🇻🇪 sovereignty and to denounce *UK complicity* in the imperialist war against *Venezuela*.
All out! Join us!
🗓 10 January ⏰ 1:00pm
🏢 Downing Street
🥁 Bring noise, flags, banners!!
#HandsOffVenezuela
https://antifascistinternational.uk/solidarity-with-the-people-of-the-bolivarian-republic-of-venezuela-and-president-nicolas-maduro-moros/
Erklärung der DKP zu den US-Angriffen gegen Venezuela!
Jetzt lesen unter unsere-zeit.de/haende-weg-von-venezuela-3-4810421/
#handsoffvenezuela#venezuela#usa
Responding to a call from the International People's Assembly, ALBA Movimientos, The Simon Bolivar Institute and The Assembly of Caribbean Peoples, activists worldwide rallied against US intervention in Venezuela and supported its recent presidential election.
From Kinshasa to Seoul, Rome to Luanda, and beyond, demonstrations defended Venezuelan democracy and sovereignty. In cities like Oslo, Vigo, and Pretoria, participants voiced solidarity with the Venezuelan people and the Bolivarian Government and condemned fascism and imperialist actions.
Click here to view the full gallery 👉🏼https://shorturl.at/YV7b0
#handsoffVenezuela#Venezuela#solidarity#internationalpeoplesassembly
🇺🇸🕊️El imperio no habla por su pueblo
⚡️Mientras Trump escala su agresión contra Venezuela, crece la resistencia interna en Estados Unidos. Organizaciones pacifistas protestaron frente al Congreso para denunciar la larga historia de intervenciones ilegales impulsadas desde la Casa Blanca.
📄 Respaldados por más de 15.000firmas, los activistas exigieron apoyo a la Resolución Constitucional 68, que ordena retirar a las Fuerzas Armadas de EE.UU. de Venezuela por carecer de aval legislativo.
👉 Incluso dentro de EE.UU., la guerra pierde legitimidad.
#NoALaGuerra
#TrumpAgresor
#VenezuelaResiste
#PuebloDeEEUUContraLaGuerra
#NoMásIntervenciones
#RespetoAlDerechoInternacional
#AntiImperialismo
#PeaceNotWar
#HandsOffVenezuela