QMenu: Display the menu title on the torn-off menu's title bar
Change-Id: If16e262a6c8b39dff517cc105cf55686d4c22582 Task-number: QTBUG-11693 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
6107f63f93
commit
445191bba8
@ -72,6 +72,7 @@
|
||||
#include <private/qpushbutton_p.h>
|
||||
#include <private/qaction_p.h>
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -127,7 +128,7 @@ public:
|
||||
setParent(parentWidget, Qt::Window | Qt::Tool);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true);
|
||||
setWindowTitle(p->windowTitle());
|
||||
updateWindowTitle();
|
||||
setEnabled(p->isEnabled());
|
||||
#if QT_CONFIG(cssparser)
|
||||
setStyleSheet(p->styleSheet());
|
||||
@ -165,6 +166,15 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void updateWindowTitle()
|
||||
{
|
||||
Q_D(QTornOffMenu);
|
||||
if (!d->causedMenu)
|
||||
return;
|
||||
const QString &cleanTitle = QPlatformTheme::removeMnemonics(d->causedMenu->title()).trimmed();
|
||||
setWindowTitle(cleanTitle);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void onTrigger(QAction *action) { d_func()->activateAction(action, QAction::Trigger, false); }
|
||||
void onHovered(QAction *action) { d_func()->activateAction(action, QAction::Hover, false); }
|
||||
@ -183,6 +193,10 @@ void QMenuPrivate::init()
|
||||
q->setAttribute(Qt::WA_X11NetWmWindowTypePopupMenu);
|
||||
defaultMenuAction = menuAction = new QAction(q);
|
||||
menuAction->d_func()->menu = q;
|
||||
QObject::connect(menuAction, &QAction::changed, [=] {
|
||||
if (!tornPopup.isNull())
|
||||
tornPopup->updateWindowTitle();
|
||||
});
|
||||
q->setMouseTracking(q->style()->styleHint(QStyle::SH_Menu_MouseTracking, 0, q));
|
||||
if (q->style()->styleHint(QStyle::SH_Menu_Scrollable, 0, q)) {
|
||||
scroll = new QMenuPrivate::QMenuScroller;
|
||||
|
@ -1,6 +1,6 @@
|
||||
CONFIG += testcase
|
||||
TARGET = tst_qmenu
|
||||
QT += widgets testlib
|
||||
QT += gui-private widgets testlib
|
||||
SOURCES += tst_qmenu.cpp
|
||||
macx:{
|
||||
OBJECTIVE_SOURCES += tst_qmenu_mac.mm
|
||||
|
@ -46,6 +46,8 @@
|
||||
#include <QTimer>
|
||||
#include <qdebug.h>
|
||||
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
Q_DECLARE_METATYPE(Qt::Key);
|
||||
Q_DECLARE_METATYPE(Qt::KeyboardModifiers);
|
||||
|
||||
@ -622,6 +624,7 @@ void tst_QMenu::tearOff()
|
||||
QScopedPointer<QMenu> menu(new QMenu(&widget));
|
||||
QVERIFY(!menu->isTearOffEnabled()); //default value
|
||||
menu->setTearOffEnabled(true);
|
||||
menu->setTitle(QLatin1String("Same &Menu"));
|
||||
menu->addAction("aaa");
|
||||
menu->addAction("bbb");
|
||||
QVERIFY(menu->isTearOffEnabled());
|
||||
@ -644,6 +647,19 @@ void tst_QMenu::tearOff()
|
||||
QVERIFY(torn);
|
||||
QVERIFY(torn->isVisible());
|
||||
|
||||
// Check menu title
|
||||
const QString cleanTitle = QPlatformTheme::removeMnemonics(menu->title()).trimmed();
|
||||
QCOMPARE(torn->windowTitle(), cleanTitle);
|
||||
|
||||
// Change menu title and check again
|
||||
menu->setTitle(QLatin1String("Sample &Menu"));
|
||||
const QString newCleanTitle = QPlatformTheme::removeMnemonics(menu->title()).trimmed();
|
||||
QCOMPARE(torn->windowTitle(), newCleanTitle);
|
||||
|
||||
// Clear menu title and check again
|
||||
menu->setTitle(QString());
|
||||
QCOMPARE(torn->windowTitle(), QString());
|
||||
|
||||
menu->hideTearOffMenu();
|
||||
QVERIFY(!menu->isTearOffMenuVisible());
|
||||
QVERIFY(!torn->isVisible());
|
||||
|
Loading…
Reference in New Issue
Block a user