diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2016-02-26 17:34:33 -0800 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@theqtcompany.com> | 2016-03-17 10:06:51 +0000 |
commit | d19c9cfd29bcb3c8fb8108bbcb29d71be19711f5 (patch) | |
tree | 7bf89afd1510079961a4f1e87977e14ef2a3a15c /src/widgets/widgets/qmenu.cpp | |
parent | b5af1bd8cff1643239809633d6be4513dd21a057 (diff) |
QMenu: Add showTearOffMenu()
The API is incomplete since we can't show a tear-off menu
programatically. This could be useful when restoring the
application state on launch.
Change-Id: Ice1911b44a5b973680f67b0150efacf3d023c2c5
Task-number: QTBUG-47974
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Diffstat (limited to 'src/widgets/widgets/qmenu.cpp')
-rw-r--r-- | src/widgets/widgets/qmenu.cpp | 49 |
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; + } } |