Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
Vaccines strengthen our immunity and protect us from many preventable diseases. 💪
They help keep individuals, families, and communities safe and healthy.
✅️Ensure you and your loved ones stay up to date and complete your vaccine doses — it’s one of the best ways to stay protected and live healthy!
Stay informed. Stay protected. Stay healthy. ✔️
# #NCDCNigeria#StayProtected#HealthyNigeria#HealthyLiving
#WellnessWednesday: Boost Your Immunity, Stay Protected! 🛡️🥦
Your immune system is your first line of defense against infections, including Mpox and other diseases. Keep it strong with these healthy habits:
🥗 Eat a balanced diet rich in fruits, vegetables, and proteins
🚶♂️ Stay active with regular exercise
💧 Hydrate: drink plenty of water daily
😴 Get enough sleep to support immune function
🧼 Practice good hygiene: wash hands frequently and keep surroundings clean
💉 Stay up to date on vaccinations where applicable
A strong immune system means a healthier you! Take charge of your wellness today.
#WellnessWednesday#HealthyLiving#BoostYourImmunity#StayProtected#NCDCNigeria
#WellnessWednesday: Boost Your Immunity, Stay Protected! 🛡️🥦
Your immune system is your first line of defense against infections, including Mpox and other diseases. Keep it strong with these healthy habits:
🥗 Eat a balanced diet rich in fruits, vegetables, and proteins
🚶♂️ Stay active with regular exercise
💧 Hydrate—drink plenty of water daily
😴 Get enough sleep to support immune function
🧼 Practice good hygiene—wash hands frequently and keep surroundings clean
💉 Stay up to date on vaccinations where applicable
A strong immune system means a healthier you! Take charge of your wellness today.
#WellnessWednesday#HealthyLiving#BoostYourImmunity#StayProtected#NCDCUpdates
#Yellow fever is a serious but vaccine preventable viral disease.
It spreads through the bite of infected mosquitoes
Protect yourself by:
▶️Getting vaccinated💉
▶️Maintaining a clean environment to stop mosquitoes from breeding.
▶️ Use insect repellent and sleep under treated nets to avoid mosquito bites.
⚠️ Report early to a nearby health facility if you feel unwell with symptoms like fever, headache, or yellowing of the eyes/skin.
#YellowFever#StayProtected#HealthyNigeria#NCDCNigeria