Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
@redfoxuz / #rebranding#restyling
Facebook o'zini aydentikasini yangiladi
Xabaringizbo'lsa 3-4 kun oldin facebook logosi yangilangani haqida xabarlar bo'lganedi, endi esa aydentikasi ham yangilandi
Batafsil: https://design.facebook.com/stories/redefining-facebooks-brand-identity/
@redfoxuz / #rebranding#restyling
Instagram o'z brendini restayling qildi!
Yangi shrift, gradient rangi yanada yorqinlashgan. Yangi shriftdan tashqari "wordmark" va dastur ikonkasi yangilangan
Batafsil: https://about.instagram.com/brand
Restayling haqida qanday fikrdasiz?
📰 New Mercedes-Benz G-Class has received a retroversion
A total of 460 of these SUVs will be produced.
💪 The Mercedes G-Class 2025 lineup features an exclusive Stronger than the 1980s version inspired by the early Gelendwagen models.
🔎 The exterior differs due to black bumpers, underbody protection, orange turn signals, wheel rims and roof rack. The body colors are borrowed from the models of the 80s. The interior combines expensive Nappa leather and checkered fabric, and on the front panel there is a plate with the serial number and the inscription Stronger than the 1980s.
🐎 The models are offered with 3.0-liter turbo engines: G500 – 449 hp, G450 d – 367 hp.
💰 The price starts from $203,000.
@CarsNews
#Mercedes#restyling
🚘 has unveiled a Phantom Goldfinger car with a hidden gold bar in the cabin
🎂 The sedan was created for the 60th anniversary of Goldfinger – a film about James Bond. In the film, a millionaire criminal smuggles gold. He smelts gold and makes it into parts for his Rolls-Royce Phantom.
🔎 The modern Phantom received a golden-black body paint, repeating the colour scheme of the car from the film, and many other references to the film. For example, the signature nose piece ‘Spirit of Ecstasy’ looks as if it was made of pure gold, which for disguise was covered with silver, partially erased. In fact, the opposite is true: the mascot was made of silver and plated with an uneven coating of 18-carat gold.
@CarsNews
#RollsRoyce#Bespoke#restyling