From 34af93e0855c803e5eeb05a305efdda794843ac5 Mon Sep 17 00:00:00 2001 From: Spiros Date: Sun, 2 Jun 2024 15:09:59 +0300 Subject: [PATCH] Fix some crashes when setting negative font size --- custombutton.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/custombutton.cpp b/custombutton.cpp index 56eeade..bf51450 100644 --- a/custombutton.cpp +++ b/custombutton.cpp @@ -25,13 +25,14 @@ void CustomButton::paintEvent(QPaintEvent *event) { for (int i = 0; i < 3; ++i) { QFont font = painter.font(); - int fontSize = 1; + int fontSize = 20; + font.setPointSize(fontSize); painter.setFont(font); QFontMetrics fm(font); QRect textRect = fm.boundingRect(rect, Qt::AlignLeft, lines[i]); - while (textRect.width() > rect.width() || textRect.height() > lineHeight) { + while ((textRect.width() > rect.width() || textRect.height() > lineHeight) && fontSize > 1) { fontSize--; font.setPointSize(fontSize); painter.setFont(font); @@ -39,7 +40,7 @@ void CustomButton::paintEvent(QPaintEvent *event) { textRect = fm.boundingRect(rect, Qt::AlignLeft, lines[i]); } - int yOffset = lineHeight * i + (lineHeight - textRect.height()) / 3; + int yOffset = lineHeight * i + (lineHeight - textRect.height()) / 2; painter.drawText(QRect(rect.left(), yOffset, rect.width(), textRect.height()), Qt::AlignLeft, lines[i]); } }