Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
👩🏻🚀💄: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #SpaceShip called "Winter x Soobin" from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #Awäa💄. Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀💄: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #SpaceShip called " Minji Moodboard " from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #Awäa💄. Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀💄: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #SpaceShip called " Yunjin Moodboard " from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #Awäa💄. Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀💄: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #SpaceShip called " Go Younjung MoodBoard" from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #Awäa💄. Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀💄: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #SpaceShip called " Eunchae Moodstagram " from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #Awäa💄. Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀💄: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #SpaceShip called " Lia MoodBoard " from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #Awäa💄. Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀💄: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #SpaceShip called " Hanni Moodstagram " from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #Awäa l. Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀💄: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #SpaceShip called "Yunjin MoodBoard " from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #Awäa💄. Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀🌧: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #Spaceship called "Rose" from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #revaya . Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀🌧: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #Spaceship called "Hueningkai" from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #revaya . Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)
👩🏻🚀🌧: *𝗕𝗢𝗢𝗠* 🤯🤯 Woah 😵💫😵... What was that 🤔🤔? Its was a super-duper big *boom* 💥💥 that just come to our 𝗯𝗲𝗮𝘂𝘁𝗶𝗳𝘂𝗹 𝗺𝗼𝗼𝗻 🌑🌕, and look. They giving us a super-duper adorable 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 📦📦, lets check it now! Ooh 😯😯, its a #Spaceship called "Kyujin" from our 𝗳𝗿𝗶𝗲𝗻𝗱𝘀 👨👩👧👦, which is #revaya . Ah, thank you @moonivrse lets check the licence first! Oh, its only for PU (Personal Use)