Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
#Ebola Virus Disease (EVD) has a high fatality rate, but early detection, supportive care, and strict adherence to preventive measures can significantly reduce risks.
⚠️ Protect yourself and others by following health advisories, practicing good hygiene, and reporting any suspected cases immediately.
#EbolaAwareness#HealthyLiving#NCDCNigeria
#Ebola is a serious infectious disease that can spread rapidly if not recognized and contained on time. The signs and symptoms usually appear 2–21 days after exposure.
⚠️ If you or someone around you notices these symptoms, do not ignore them. Seek medical attention immediately and avoid contact with others until cleared by health professionals.
🛡️ Protecting yourself also protects your family, friends, and community.
Let’s work together to stop the spread of Ebola.
#EbolaAwareness#HealthyLiving#StaySafe
#Ebola is caused by the Ebolavirus — a group of viruses with several species, including Zaire, Sudan, Bundibugyo, Taï Forest, and Reston ebolavirus (which affects animals but not humans).
Knowing the cause helps us strengthen prevention and response efforts. 💪🏾
Stay Safe, Stay Protected!
#EbolaAwareness#HealthSecurity#NCDCNigeria