Fix the Increment boxes of the Auto numbering panel cut off on Windows

Each Increment spin box had a fixed maximum width of 55 px. The Windows
11 style puts the up and down arrows side by side, which leaves almost
nothing of 55 px for the number (#1566). The boxes now take the width
their style asks for.

Test: tst_autonumincrementwidth runs the editor under a style that
widens spin boxes the way the Windows 11 style does and checks each
Increment box is at least as wide as the style needs: 55 px against 81
px before this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-21 21:26:57 +13:00
parent 672ba7c409
commit 537e3c3c10
3 changed files with 68 additions and 18 deletions
+4
View File
@@ -312,6 +312,10 @@ qet_add_app_test(tst_folioimageload tst_folioimageload.cpp)
# selection has nothing to edit for a moment (#1439).
qet_add_app_test(tst_selectionpanelheight tst_selectionpanelheight.cpp)
# The Auto numbering panel's Increment spin boxes get the width their style
# asks for; a fixed 55 px cut the number off on Windows (#1566).
qet_add_app_test(tst_autonumincrementwidth tst_autonumincrementwidth.cpp)
# Opening a project before the elements panel's first reload() left its tree
# item detached, and selecting the item's first child crashed in QTreeModel
# (pre-existing since a82f6de23).
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "qetapptest.h"
#include <QDockWidget>
#include <QProxyStyle>
#include <QSpinBox>
namespace {
// Spin boxes as wide as the Windows 11 style draws them: its up and down
// buttons sit side by side, so a spin box needs far more room than with
// the buttons stacked.
class WideSpinBoxStyle : public QProxyStyle
{
public:
QSize sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &size, const QWidget *widget) const override
{
QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
if (type == CT_SpinBox)
s.rwidth() += 40;
return s;
}
};
}
// The Increment spin boxes of the Auto numbering panel get the width their
// style asks for (#1566). A fixed 55 px maximum cut off the number on
// Windows.
class tst_autonumincrementwidth : public QObject
{
Q_OBJECT
private slots:
void incrementFitsItsStyle()
{
QApplication::setStyle(new WideSpinBoxStyle);
QETDiagramEditor *editor = QetAppTest::editor();
QVERIFY(editor);
editor->resize(1600, 1000);
editor->show();
QVERIFY(QTest::qWaitForWindowExposed(editor));
const QStringList names{"m_conductor_increase_sb",
"m_element_increase_sb",
"m_folio_increase_sb"};
for (const QString &name : names) {
auto spin_box = editor->findChild<QSpinBox *>(name);
QVERIFY2(spin_box, qPrintable(name));
QVERIFY2(spin_box->isVisible(), qPrintable(name));
QVERIFY2(spin_box->width() >= spin_box->minimumSizeHint().width(),
qPrintable(QString("%1 is %2 px, its style needs %3 px")
.arg(name)
.arg(spin_box->width())
.arg(spin_box->minimumSizeHint().width())));
}
}
};
QET_APP_TEST_MAIN(tst_autonumincrementwidth)
#include "tst_autonumincrementwidth.moc"