Skip to content

Commit 264dfad

Browse files
committed
1
1 parent 904ecfe commit 264dfad

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/Plugins/Qt/QTMCodePopup.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "scheme.hpp"
1515

1616
#include <QAction>
17+
#include <QFontMetrics>
1718
#include <algorithm>
1819
#include <cmath>
1920

@@ -106,11 +107,11 @@ QTMCodePopup::updatePosition (qt_renderer_rep* ren) {
106107
move (pos_x, pos_y);
107108
}
108109

109-
// ????????????????????
110+
// 按按钮内容与字体动态计算弹窗尺寸,避免跨平台比例失衡。
110111
void
111112
QTMCodePopup::autoSize () {
112-
const int fallbackWidth = 180;
113-
const int fallbackHeight= 36;
113+
const int fallbackWidth = 120;
114+
const int fallbackHeight= 28;
114115
cached_width = fallbackWidth;
115116
cached_height = fallbackHeight;
116117
if (layout && copyBtn && langBtn) {
@@ -121,8 +122,20 @@ QTMCodePopup::autoSize () {
121122
copyBtn->sizeHint ().width () + langBtn->sizeHint ().width () + spacing;
122123
const int btnH= std::max (copyBtn->sizeHint ().height (),
123124
langBtn->sizeHint ().height ());
124-
cached_width = std::max (btnW + lm + rm, fallbackWidth);
125-
cached_height = std::max (btnH + tm + bm, fallbackHeight);
125+
126+
// 动态兜底:用当前字体度量计算最小按钮尺寸,避免固定值在 Linux 上显得过大。
127+
QFontMetrics fmCopy (copyBtn->font ());
128+
QFontMetrics fmLang (langBtn->font ());
129+
const int copyTextW= fmCopy.boundingRect (copyBtn->text ()).width ();
130+
const int langTextW= fmLang.boundingRect (langBtn->text ()).width ();
131+
const int copyMinW = copyTextW + 20;
132+
const int langMinW = langTextW + 20;
133+
const int textMinH = std::max (fmCopy.height (), fmLang.height ()) + 10;
134+
135+
const int dynamicMinW= copyMinW + langMinW + spacing + lm + rm;
136+
const int dynamicMinH= textMinH + tm + bm;
137+
cached_width = std::max (btnW + lm + rm, dynamicMinW);
138+
cached_height = std::max (btnH + tm + bm, dynamicMinH);
126139
}
127140
setFixedSize (cached_width, cached_height);
128141
}

0 commit comments

Comments
 (0)