Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
Genetically edited pig hearts and kidneys can act as temporary "bridges" for critically ill patients — buying time for recovery or a human transplant while researchers work on long‑term safety. 🐷❤️🩺
[Read more]
@googlefactss#Xenotransplantation#Bioethics
🌱🐾 Colombia passes historic “Law of Empathy”!
Schools across the country will now teach children compassion for animals and respect for nature. The law requires all educational institutions — from kindergartens to high schools — to integrate ethical treatment of animals and biodiversity protection into school projects.
Key points:
High school students can complete community service in animal shelters and wildlife rehabilitation centers.
Programs recognize animals as sentient beings — capable of feeling pain and emotions.
A national network of teachers will share experiences and best practices in fostering respect for life.
Senator Andrea Padilla, the law’s initiator, said:
"Education saves lives and changes the world. We want new generations to grow up as fair and compassionate citizens toward all forms of life."
Colombia is now one of the first Latin American countries to make humane education mandatory — a potential model for other countries worldwide! 🌎💚
#Colombia#LawOfEmpathy#AnimalProtection#EcoEducation#Bioethics☘️Read the latest environmental news on the @ekologuz page. Follow us and send your suggestions and wishes via @eklguz_bot
Instagram | Facebook | Twitter | Sayt | Youtube