Skip to content

Commit e5f66dd

Browse files
fix(shot): dynamically calculate size tips dimensions based on font size
Use fontMetrics() to compute width and height instead of hardcoded setFixedSize(90, 30), ensuring size tips display correctly on different font sizes and screen scaling ratios (e.g., 125% scale with font size 20). bug: https://pms.uniontech.com/bug-view-346697.html
1 parent 08820ad commit e5f66dd

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/widgets/toptips.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ TopTips::TopTips(DWidget *parent)
2222
: QLabel(parent)
2323
{
2424
qCDebug(dsrApp) << "TopTips constructor called.";
25-
setFixedSize(90, 30);
2625
setAttribute(Qt::WA_TransparentForMouseEvents, true);
2726
// this->setStyleSheet(" TopTips { background-color: transparent;"
2827
// "border-image: url(:/resources/images/action/sizetip.png) no-repeat;"
@@ -46,15 +45,17 @@ void TopTips::setContent(const QSize &size)
4645
if(m_showRecorderTips && size.width() * size.height() > 1920 * 1080 && size.width() != m_width && size.height() != m_height) {
4746
// 1920 / 1080 = w / h
4847
// w h 等比缩放
49-
setFixedSize(500, 30);
5048
int h = static_cast<int>(sqrt(1920.0 * 1080 * size.height() / size.width()));
5149
int w = static_cast<int>(sqrt(1920.0 * 1080 * size.width() / size.height()));
5250
QString recorderTips = tr(" Adjust the recording area within %1*%2 to get better video effect");
5351
qCDebug(dsrApp) << "Setting content with recording area adjustment tip:" << w << "x" << h;
54-
setText(text + recorderTips.arg(w).arg(h));
52+
QString fullText = text + recorderTips.arg(w).arg(h);
53+
setText(fullText);
54+
setFixedSize(fontMetrics().horizontalAdvance(fullText), fontMetrics().boundingRect(fullText).height());
5555
} else {
5656
qCDebug(dsrApp) << "Setting content size:" << size;
5757
setText(text);
58+
setFixedSize(fontMetrics().horizontalAdvance(text), fontMetrics().boundingRect(text).height());
5859
}
5960
}
6061

0 commit comments

Comments
 (0)