diff options
author | Pierre Rossi <pierre.rossi@nokia.com> | 2009-12-03 23:04:09 (GMT) |
---|---|---|
committer | Pierre Rossi <pierre.rossi@nokia.com> | 2009-12-04 18:43:37 (GMT) |
commit | 8529a8cbb0c6404c758b5efc650186d740b0e09f (patch) | |
tree | d34ea445050b249573c006fde64dfbbc45178cab /src/gui/widgets/qpushbutton.cpp | |
parent | f0bb9bc5b0f4c20536d6c77624bd148389b78c06 (diff) | |
download | Qt-8529a8cbb0c6404c758b5efc650186d740b0e09f.zip Qt-8529a8cbb0c6404c758b5efc650186d740b0e09f.tar.gz Qt-8529a8cbb0c6404c758b5efc650186d740b0e09f.tar.bz2 |
Fixes problem with QMenu when it's populated on the aboutToShow
When the menu is populated that late, if the menu is to go off-screen,
then it is moved and ends up covering its originating button.
Includes some code cleanup thanks to Thierry's tips.
Reviewed-by: Gabriel
Reviewed-by: Thierry
Diffstat (limited to 'src/gui/widgets/qpushbutton.cpp')
-rw-r--r-- | src/gui/widgets/qpushbutton.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/gui/widgets/qpushbutton.cpp b/src/gui/widgets/qpushbutton.cpp index eb34336..849bc43 100644 --- a/src/gui/widgets/qpushbutton.cpp +++ b/src/gui/widgets/qpushbutton.cpp @@ -63,6 +63,7 @@ #include "qaccessible.h" #endif +#include "private/qmenu_p.h" #include "private/qpushbutton_p.h" QT_BEGIN_NAMESPACE @@ -575,12 +576,33 @@ void QPushButtonPrivate::_q_popupPressed() return; menu->setNoReplayFor(q); + + QPoint menuPos = adjustedMenuPosition(); + + QPointer<QPushButton> guard(q); + QMenuPrivate::get(menu)->causedPopup.widget = guard; + + //Because of a delay in menu effects, we must keep track of the + //menu visibility to avoid flicker on button release + menuOpen = true; + menu->exec(menuPos); + if (guard) { + menuOpen = false; + q->setDown(false); + } +} + +QPoint QPushButtonPrivate::adjustedMenuPosition() +{ + Q_Q(QPushButton); + bool horizontal = true; #if !defined(QT_NO_TOOLBAR) QToolBar *tb = qobject_cast<QToolBar*>(parent); if (tb && tb->orientation() == Qt::Vertical) horizontal = false; #endif + QWidgetItem item(q); QRect rect = item.geometry(); rect.setRect(rect.x() - q->x(), rect.y() - q->y(), rect.width(), rect.height()); @@ -603,17 +625,10 @@ void QPushButtonPrivate::_q_popupPressed() else x -= menuSize.width(); } - QPointer<QPushButton> guard(q); - //Because of a delay in menu effects, we must keep track of the - //menu visibility to avoid flicker on button release - menuOpen = true; - menu->exec(QPoint(x, y)); - if (guard) { - menuOpen = false; - q->setDown(false); - } + return QPoint(x,y); } + #endif // QT_NO_MENU void QPushButtonPrivate::resetLayoutItemMargins() |