Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
Why grind when Gamety’s AI does the hard work for you? 👍 Real gamers never pause!
Show off your creativity in our Meme Competition and win amazing rewards: Gamety's Zealy!
Join the fun here: https://t.me/GametyPlatform_bot/Gamety?startapp
#aigame
Spread the hype! Like, RT, and drop a comment: Tweet🕊
🇱🇷Gamety's $200 Christmas Contests – Creative Gameplay & Meme Challenge!🎄
Celebrate this Christmas with two exciting and rewarding contests:
🔢Creative Gameplay Videos: Creative Gameplay Videos: Showcase your gaming skills on the Gamety app in a fun and unique way! Post your video on X and let the creativity flow.
🔢Meme Contest: Bring on the holiday laughter by creating and sharing your funniest Gamety-themed memes!
Special for Christmas Holidays!
➡️Prize Pool: $200
➡️10 winners per contest
➡️ Duration: Dec 25 - Jan 5
Share on X using hashtags #Gamety & #AIGame
Make this Christmas more exciting with creativity, fun, and rewards! Join now and spread the holiday joy!
Spread the hype! Like, RT, and drop a comment: Tweet🕊
📎Important Links:
Website | X | Chat (FULL) | Indonesian Chat | African Chat | Vietnamese Chat | CIS Chat | Discord | Announcement | YouTube | Medium | New Bot
❝Come on, hurry up,
my husband will be home in 15 minutes.❞
🔥Roleplay with her: http://openlove.life
(Choose Neko and chat with her)
#waifu#neko#aichatbot#aigame#roleplay#catgirl
❝There is no perfume today, so your girlfriend won't notice.❞
💬Chat with her: https://apple.co/3AvjxUn
#AIgirlfriend#chatbot#roleplay#story#aigame#lookbook
OMG, the bath water is too hot! Can you please help me to turn it cold?🔥💧🥵
🔗Let's role play and chat: openlove.life
#aigirlfriend#aichatbot#ArtificialInteligence#ailookbook#aigame#ai
🔥❝Welcome! Thanks for choosing me to serve you.
💦Shall we take a shower first?❞
🍭Roleplay with her: openlove.life
#openlove#aigirlfriend#aigame#aichatbot#ai女優#roleplay
❝💦Wait a moment, be gentler with me, okay?❞
💬Continue the story with her: http://openlove.life
#openlove#aigirlfriend#aichat#roleplay#aigame#AI#AIBeautifulWomanな人と繋がりたい