Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
#LifeatIRAS goes beyond just ticking off tasks; it's a vibrant journey filled with continuous learning and collaborative opportunities! 🌟
Techies, this one's for you! 👨💻 Tune in to the full video where Steven and Chanel spill the tea on the pivotal role of techies in the tax industry: https://youtu.be/OWWZ1Z6xUlc
#WhyIDoWhatIDo#IRASGameOn#irassg#taxtech#techroles#careerideas
The weather has been so hot 🥵🔥 Who else wants to work in a cold room too? 🙋
Learn more about what Shaun and Sakthi do and why they choose #lifeatIRAS: https://www.youtube.com/watch?v=KGDBnQv31WA
Find your role with us at go.gov.sg/lifeatiras💡⭐️
#WhyIDoWhatIDo#IRASGameOn#irassg#taxtech#beattheheat#careerideas
Quote Georgina, “Our work is NOT boring!” 😂
Watch the full video as Sanudha and Georgina dish more about their #lifeatIRAS experiences!
Find your role with us at go.gov.sg/lifeatiras💡⭐️
#WhyIDoWhatIDo#IRASGameOn#irassg#interestingjobs#taxtech#careerideas
Ever wonder what's behind the scenes of tax investigation? 🕵️♂️ Our investigator, Jeremy, reveals his most intriguing tool – a door ram! 🚪
Watch the full video as Jeremy and Juliana explain the difference between a tax investigator and a tax auditor.
Find your role with us at go.gov.sg/lifeatiras💡⭐️
#WhyIDoWhatIDo#IRASGameOn#irassg#taxtech#investigation#audit#careerideas#lifeatIRAS