summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qmenu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qmenu.cpp')
-rw-r--r--src/widgets/widgets/qmenu.cpp49
1 files changed, 44 insertions, 5 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 1b9e31968a..274570b22a 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -1948,7 +1948,7 @@ bool QMenu::isTearOffEnabled() const
contents in a new window. When the menu is in this mode and the menu
is visible returns \c true; otherwise false.
- \sa hideTearOffMenu(), isTearOffEnabled()
+ \sa showTearOffMenu(), hideTearOffMenu(), isTearOffEnabled()
*/
bool QMenu::isTearOffMenuVisible() const
{
@@ -1958,15 +1958,54 @@ bool QMenu::isTearOffMenuVisible() const
}
/*!
+ \since 5.7
+
+ This function will forcibly show the torn off menu making it
+ appear on the user's desktop at the specified \e global position \a pos.
+
+ \sa hideTearOffMenu(), isTearOffMenuVisible(), isTearOffEnabled()
+*/
+void QMenu::showTearOffMenu(const QPoint &pos)
+{
+ Q_D(QMenu);
+ if (!d->tornPopup)
+ d->tornPopup = new QTornOffMenu(this);
+ const QSize &s = sizeHint();
+ d->tornPopup->setGeometry(pos.x(), pos.y(), s.width(), s.height());
+ d->tornPopup->show();
+}
+
+/*!
+ \overload
+ \since 5.7
+
+ This function will forcibly show the torn off menu making it
+ appear on the user's desktop under the mouse currsor.
+
+ \sa hideTearOffMenu(), isTearOffMenuVisible(), isTearOffEnabled()
+*/
+void QMenu::showTearOffMenu()
+{
+ showTearOffMenu(QCursor::pos());
+}
+
+/*!
This function will forcibly hide the torn off menu making it
- disappear from the users desktop.
+ disappear from the user's desktop.
- \sa isTearOffMenuVisible(), isTearOffEnabled()
+ \sa showTearOffMenu(), isTearOffMenuVisible(), isTearOffEnabled()
*/
void QMenu::hideTearOffMenu()
{
- if (QWidget *w = d_func()->tornPopup)
- w->close();
+ Q_D(QMenu);
+ if (d->tornPopup) {
+ d->tornPopup->close();
+ // QTornOffMenu sets WA_DeleteOnClose, so we
+ // should consider the torn-off menu deleted.
+ // This way showTearOffMenu() will not try to
+ // reuse the dying torn-off menu.
+ d->tornPopup = Q_NULLPTR;
+ }
}