Don't treat the ampersand in a titlebar as a mnemonic
As the mnemonic has no meaning when it is in a dockwidget title, we should just treat it as a literal ampersand instead and display it as such. Fixes: QTBUG-54485 Change-Id: I96c856ce2771a68d226f48f8f47affc24f1c53cd Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
parent
c961d1a6d2
commit
e70230405d
@ -3922,7 +3922,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
|
||||
titleRect.width());
|
||||
|
||||
const auto text = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
|
||||
proxy()->drawItemText(p, titleRect, Qt::AlignCenter | Qt::TextShowMnemonic, dwOpt->palette,
|
||||
proxy()->drawItemText(p, titleRect, Qt::AlignCenter, dwOpt->palette,
|
||||
dwOpt->state & State_Enabled, text, QPalette::WindowText);
|
||||
}
|
||||
p->restore();
|
||||
|
@ -2096,7 +2096,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
|
||||
|
||||
const int indent = p->fontMetrics().descent();
|
||||
proxy()->drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1),
|
||||
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
|
||||
Qt::AlignLeft | Qt::AlignVCenter, dwOpt->palette,
|
||||
dwOpt->state & State_Enabled, dwOpt->title,
|
||||
QPalette::WindowText);
|
||||
|
||||
|
@ -1256,7 +1256,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
|
||||
Qt::ElideRight, titleRect.width());
|
||||
proxy()->drawItemText(painter,
|
||||
titleRect,
|
||||
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
|
||||
Qt::AlignLeft | Qt::AlignVCenter, dwOpt->palette,
|
||||
dwOpt->state & State_Enabled, titleText,
|
||||
QPalette::WindowText);
|
||||
}
|
||||
|
@ -4224,7 +4224,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
|
||||
|
||||
QString titleText = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, r.width());
|
||||
drawItemText(p, r,
|
||||
alignment | Qt::TextShowMnemonic, dwOpt->palette,
|
||||
alignment, dwOpt->palette,
|
||||
dwOpt->state & State_Enabled, titleText,
|
||||
QPalette::WindowText);
|
||||
|
||||
|
@ -1825,7 +1825,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
|
||||
titleRect.height(), titleRect.width());
|
||||
}
|
||||
proxy()->drawItemText(p, titleRect,
|
||||
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette,
|
||||
Qt::AlignLeft | Qt::AlignVCenter, palette,
|
||||
dwOpt->state & State_Enabled, dwOpt->title,
|
||||
floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
|
||||
p->setFont(oldFont);
|
||||
|
@ -55,6 +55,7 @@
|
||||
|
||||
#include <private/qwidgetresizehandler_p.h>
|
||||
#include <private/qstylesheetstyle_p.h>
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
#include "qdockwidget_p.h"
|
||||
#include "qmainwindowlayout_p.h"
|
||||
|
@ -108,6 +108,7 @@ public:
|
||||
// QMainWindow *findMainWindow(QWidget *widget) const;
|
||||
QRect undockedGeometry;
|
||||
QString fixedWindowTitle;
|
||||
QString dockedWindowTitle;
|
||||
|
||||
bool mousePressEvent(QMouseEvent *event);
|
||||
bool mouseDoubleClickEvent(QMouseEvent *event);
|
||||
|
@ -71,6 +71,7 @@ private slots:
|
||||
void restoreStateOfFloating();
|
||||
void restoreDockWidget();
|
||||
void restoreStateWhileStillFloating();
|
||||
void setWindowTitle();
|
||||
// task specific tests:
|
||||
void task165177_deleteFocusWidget();
|
||||
void task169808_setFloating();
|
||||
@ -993,7 +994,54 @@ void tst_QDockWidget::taskQTBUG_9758_undockedGeometry()
|
||||
QVERIFY(dock1.y() >= 0);
|
||||
}
|
||||
|
||||
void tst_QDockWidget::setWindowTitle()
|
||||
{
|
||||
QMainWindow window;
|
||||
QDockWidget dock1(&window);
|
||||
QDockWidget dock2(&window);
|
||||
const QString dock1Title = QStringLiteral("&Window");
|
||||
const QString dock2Title = QStringLiteral("&Modifiable Window [*]");
|
||||
|
||||
dock1.setWindowTitle(dock1Title);
|
||||
dock2.setWindowTitle(dock2Title);
|
||||
window.addDockWidget(Qt::RightDockWidgetArea, &dock1);
|
||||
window.addDockWidget(Qt::RightDockWidgetArea, &dock2);
|
||||
window.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
||||
|
||||
QCOMPARE(dock1.windowTitle(), dock1Title);
|
||||
QCOMPARE(dock2.windowTitle(), dock2Title);
|
||||
|
||||
dock1.setFloating(true);
|
||||
dock1.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&dock1));
|
||||
QCOMPARE(dock1.windowTitle(), dock1Title);
|
||||
dock1.setFloating(false);
|
||||
QCOMPARE(dock1.windowTitle(), dock1Title);
|
||||
dock1.setFloating(true);
|
||||
dock1.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&dock1));
|
||||
const QString changed = QStringLiteral("Changed ");
|
||||
dock1.setWindowTitle(QString(changed + dock1Title));
|
||||
QCOMPARE(dock1.windowTitle(), QString(changed + dock1Title));
|
||||
dock1.setFloating(false);
|
||||
QCOMPARE(dock1.windowTitle(), QString(changed + dock1Title));
|
||||
|
||||
dock2.setWindowModified(true);
|
||||
QCOMPARE(dock2.windowTitle(), dock2Title);
|
||||
dock2.setFloating(true);
|
||||
dock2.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&dock2));
|
||||
QCOMPARE(dock2.windowTitle(), dock2Title);
|
||||
dock2.setWindowModified(false);
|
||||
QCOMPARE(dock2.windowTitle(), dock2Title);
|
||||
dock2.setFloating(false);
|
||||
QCOMPARE(dock2.windowTitle(), dock2Title);
|
||||
dock2.setFloating(true);
|
||||
dock2.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&dock2));
|
||||
QCOMPARE(dock2.windowTitle(), dock2Title);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QDockWidget)
|
||||
#include "tst_qdockwidget.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user