mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-04-21 00:13:18 +03:00
Fix some crashes when setting negative font size
This commit is contained in:
@@ -25,13 +25,14 @@ void CustomButton::paintEvent(QPaintEvent *event) {
|
|||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
QFont font = painter.font();
|
QFont font = painter.font();
|
||||||
int fontSize = 1;
|
int fontSize = 20;
|
||||||
|
font.setPointSize(fontSize);
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
|
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
QRect textRect = fm.boundingRect(rect, Qt::AlignLeft, lines[i]);
|
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--;
|
fontSize--;
|
||||||
font.setPointSize(fontSize);
|
font.setPointSize(fontSize);
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
@@ -39,7 +40,7 @@ void CustomButton::paintEvent(QPaintEvent *event) {
|
|||||||
textRect = fm.boundingRect(rect, Qt::AlignLeft, lines[i]);
|
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]);
|
painter.drawText(QRect(rect.left(), yOffset, rect.width(), textRect.height()), Qt::AlignLeft, lines[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user