Есть у QLabel есть одна особенность. Её минимальный размер определяется текстом, который в неё записан. Это приводит к тому что длинный текст принудительно увеличивает ширину интерфейса.
В большинстве случаев это выглядит плохо.
Как с этим бороться?
🔸 Обрезать текст заранее, задав лимит по длине строки. В этом случае мы теряем часть визуальной информации. Не всегда угадаешь нужный размер. В разных OS шрифт используется разный.
🔸 Делать перенос строки. Тогда мы получим изменение размера в другую сторону, что тоже поломает интерфейс.
🔸 Переопределить paintEvent() и сделать кастомный рендеринг текста. Можно, но слишком сложно для такой задачи.
Проще всего обрезать текст под текущий размер виджета используя класс QFontMetrics.
Он имеет готовый метод elidedText(), который просто вызываем по событию resizeEvent.
Я также добавил установку ToolTip чтобы всегда можно было увидеть полный текст при наведении курсора.
🌎 Код здесь
#qt#source
🚘 Skytop with "the most powerful V8 engine ever" unveiled
The latest BMW Skytop has made its debut at the Villa d'Este 2024 classic car show on the shores of Lake Como.
The two-seater car has a rigid roof that can be removed manually and the rear window can be raised and lowered with a button. "Chrome shadow effect" is designed specifically for the Skytop.
According to the manufacturer, the car has been given the "most powerful V8 engine", which is supposedly the same 4.4-litre 625bhp engine used in the M8 Competition.
In creating the Skytop, BMW decided to pay homage to the brand's classic models such as the Z8 and 503. Although the car is only a concept car at the moment, BMW has not ruled out the possibility of a limited production run.
@CarsNews
#BMW#conceptcar#roadster
✨ Presenting the Cadillac Sollei convertible with a stunning mushroom-based interior! 🍄
This concept, based on the production platform of the electric Celestiq, features a unique body design and interior finish using five different wood types and the bio-material Fine Mycelium, including mushroom mycelium.
The Sollei showcases the revival of the classic Manila Cream color from the late 1950s. While specific technical details are yet to be revealed, the production Celestiq is equipped with electric motors producing around 600 horsepower.
#Cadillac#Sollei#Celestiq#ElectricCar#Auto#ConceptCar🚗💫
🚗✨ Introducing the Alpenglow Hy6 by Alpine! 🌟
This stunning concept car is the evolution of the Alpenglow Hy4, showcasing a powerful V6 engine that delivers an impressive 730 hp and 770 Nm of torque—all powered by hydrogen! 💨🔋
Built on a lightweight carbon LMP3 chassis, the Hy6 promises thrilling performance and cutting-edge technology. Production is on the horizon, with the possibility of an all-electric powertrain on the assembly line! ⚡️🌍
#Alpine#AlpenglowHy6#HydrogenPower#ElectricFuture#CarEnthusiast#ConceptCar#Innovation#Auto🚀