From 7944423bfaec48e5c7642a042bede1557b1beff2 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 19 Oct 2017 09:36:15 +0200 Subject: Add clarifying documentation for QLayout::removeWidget() Change-Id: I6c256c6c5cdfed6ceb45758d708fdc8f74d2939f Reviewed-by: Leena Miettinen --- src/widgets/kernel/qlayout.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index 1e455b0d64..f3db4f4e2d 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -1350,7 +1350,8 @@ QRect QLayout::alignmentRect(const QRect &r) const /*! Removes the widget \a widget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable - geometry or to put the widget back into a layout. + geometry or to put the widget back into a layout or to explicitly + hide it if necessary. \b{Note:} The ownership of \a widget remains the same as when it was added. -- cgit v1.2.3 From 7e7683cabb8df58097c5bc4638a2e08cf6e6ff71 Mon Sep 17 00:00:00 2001 From: Yulong Bai Date: Tue, 17 Oct 2017 14:41:42 +0200 Subject: QAction: fix ::setData() always emits changed() QAction::setData() always emits changed() even without actual data change. Original code lacks a guard to check if the data changes. According to http://doc.qt.io/qt-4.8/signalsandslots.html, adding guard also benefits to prevent infinite looping in case of cyclic connections. Task-number: QTBUG-62006 Change-Id: I776369b668082f9f02e4502a36b1ae234ee7e079 Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qaction.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp index f1788bb3f4..7754defaac 100644 --- a/src/widgets/kernel/qaction.cpp +++ b/src/widgets/kernel/qaction.cpp @@ -1118,6 +1118,8 @@ void QAction::setData(const QVariant &data) { Q_D(QAction); + if (d->userData == data) + return; d->userData = data; d->sendDataChanged(); } -- cgit v1.2.3 From 3b8f828174f08d9037a0947b8709648ac37cdc36 Mon Sep 17 00:00:00 2001 From: Maciej Czarnecki Date: Mon, 21 Aug 2017 13:28:51 +0200 Subject: QWizard: Do not remove the Next button's shortcut Currently on Windows, the Next button's shortcut doesn't work, because QWizard overrides it with an empty key sequence. The key sequence should be changed only if isVistaThemeEnabled() returns true. Task-number: QTBUG-46894 Change-Id: I54f26388b167973cc8065a867d9e771c1e6a2a72 Reviewed-by: Friedemann Kleint --- src/widgets/dialogs/qwizard.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 1984cb0a89..a4ea7ae8de 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -1468,8 +1468,8 @@ void QWizardPrivate::updateButtonTexts() // even in RTL mode, so do the same, even if it might be counter-intuitive. // The shortcut for 'back' is set in class QVistaBackButton. #if QT_CONFIG(shortcut) - if (btns[QWizard::NextButton]) - btns[QWizard::NextButton]->setShortcut(isVistaThemeEnabled() ? QKeySequence(Qt::ALT | Qt::Key_Right) : QKeySequence()); + if (btns[QWizard::NextButton] && isVistaThemeEnabled()) + btns[QWizard::NextButton]->setShortcut(QKeySequence(Qt::ALT | Qt::Key_Right)); #endif } -- cgit v1.2.3 From 7a26582807b06d16d8d1b909a0c5ea34bcecfa42 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 9 Oct 2017 11:47:43 +0200 Subject: Make sure that QAccessibleWindowContainer::childCount is valid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When embedding foreign windows, we won't be able to return a valid child accessible interface, so do not report it at all. Supporting foreign windows properly is platform specific and something to consider, but at least we shouldn't crash. Task-number: QTBUG-63451 Change-Id: I19350cf97dc8d0c3f3052411eba0eee5f750dbab Reviewed-by: Jan Arve Sæther --- src/widgets/accessible/simplewidgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index 73de51ff45..bacb00fe2e 100644 --- a/src/widgets/accessible/simplewidgets.cpp +++ b/src/widgets/accessible/simplewidgets.cpp @@ -953,7 +953,7 @@ QAccessibleWindowContainer::QAccessibleWindowContainer(QWidget *w) int QAccessibleWindowContainer::childCount() const { - if (container()->containedWindow()) + if (container()->containedWindow() && QAccessible::queryAccessibleInterface(container()->containedWindow())) return 1; return 0; } -- cgit v1.2.3 From a4f9cf23444dd76a11d4eb67c4ea65d5c3948894 Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Sat, 29 Jul 2017 11:28:13 +0200 Subject: Disable window shortcuts if there is a window modal dialog If a window is blocked by a WindowModal dialog, it should not be possible to trigger window shortcuts on that window if it receives a WindowActivate event. This currently happens if the blocked window gets clicked, because the window becomes the active_window and then QApplication sends it a WindowActivate event (this doesn't happen with application modal dialogs). The correctWidgetContext() function calls QApplicationPrivate::tryModalHelper() only if the shortcut context is ApplicationShortcut. This patch makes it call even if the shortcut context is WindowShortcut. Change-Id: Iff87d85bcae603a6a24128e0cedfa9d33b6485fd Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qshortcut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index f944a7097b..32600d4152 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -205,7 +205,7 @@ static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidge #if defined(DEBUG_QSHORTCUTMAP) qDebug().nospace() << "..true [Pass-through]"; #endif - return true; + return QApplicationPrivate::tryModalHelper(w, nullptr); } #if QT_CONFIG(graphicsview) -- cgit v1.2.3 From 937ded010b09250c6ab9a57917f2e430fb5875f5 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 28 Oct 2017 19:13:58 +0200 Subject: QListView: make sure to respect grid size during dataChanged() handling When the dataChanged() signal is handled by QIconModeViewBase, the size of the items are recalculated. During this operation the optional grid size is not taken into account which leads to a screwed up layout. This patch adds the missing check similar it is done in doStaticLayout()/doDynamicLayout(). Task-number: QTBUG-45427 Change-Id: Iba7adb44b1510c511a69c289ccb4f168992a6871 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qlistview.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 9e959c8e1e..9217fec10e 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -2874,10 +2874,19 @@ void QIconModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) void QIconModeViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { if (column() >= topLeft.column() && column() <= bottomRight.column()) { - QStyleOptionViewItem option = viewOptions(); - int bottom = qMin(items.count(), bottomRight.row() + 1); + const QStyleOptionViewItem option = viewOptions(); + const int bottom = qMin(items.count(), bottomRight.row() + 1); + const bool useItemSize = !dd->grid.isValid(); for (int row = topLeft.row(); row < bottom; ++row) - items[row].resize(itemSize(option, modelIndex(row))); + { + QSize s = itemSize(option, modelIndex(row)); + if (!useItemSize) + { + s.setWidth(qMin(dd->grid.width(), s.width())); + s.setHeight(qMin(dd->grid.height(), s.height())); + } + items[row].resize(s); + } } } -- cgit v1.2.3 From 92c61b11c1704450adfa3a8ac839478c0f3dd19d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Oct 2017 15:23:39 +0200 Subject: Windows: Use SM_CXSMICON instead of SM_CXICON for the tray icon size Partially reverts b465fe759695bb7e1de693c3d4d20acfd2c49779. Task-number: QTBUG-63447 Change-Id: Iaf8a54b59a054e33811f65f64322af3aa746885e Reviewed-by: Oliver Wolff --- src/widgets/util/qsystemtrayicon_win.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/util/qsystemtrayicon_win.cpp b/src/widgets/util/qsystemtrayicon_win.cpp index 3f007f24c1..57d46912e0 100644 --- a/src/widgets/util/qsystemtrayicon_win.cpp +++ b/src/widgets/util/qsystemtrayicon_win.cpp @@ -313,9 +313,8 @@ HICON QSystemTrayIconSys::createIcon() const QIcon icon = q->icon(); if (icon.isNull()) return oldIcon; - const QSize requestedSize = QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA - ? QSize(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)) - : QSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); + // When merging this to 5.10, change at src/plugins/platforms/windows/qwindowssystemtrayicon.cpp:351. + const QSize requestedSize = QSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); const QSize size = icon.actualSize(requestedSize); const QPixmap pm = icon.pixmap(size); if (pm.isNull()) -- cgit v1.2.3 From b4f4c384d9ee7cf93cc3db289a7d4275ac10a618 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 28 Oct 2017 13:20:53 +0200 Subject: QHeaderView: Honor maximumSectionSize property during resizeSections() Resizing a QTreeeView section with double click or resizeColumnToContents() does not respect the maximumSectionSize when the resize mode is Interactive or Fixed. Since the documentation of maximumSectionSize states that it should honor this property for those cases either the documentation or implementation is incorrect. This patch fixes the latter. Task-number: QTBUG-64036 Change-Id: Ic14c8e444d50b9c50a117efed19d0bca7ec1cf82 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qheaderview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 213cc96b03..3af191b06c 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3364,7 +3364,7 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool // because it isn't stretch, determine its width and remove that from lengthToStretch int sectionSize = 0; if (resizeMode == QHeaderView::Interactive || resizeMode == QHeaderView::Fixed) { - sectionSize = headerSectionSize(i); + sectionSize = qBound(q->minimumSectionSize(), headerSectionSize(i), q->maximumSectionSize()); } else { // resizeMode == QHeaderView::ResizeToContents int logicalIndex = q->logicalIndex(i); sectionSize = qMax(viewSectionSizeHint(logicalIndex), -- cgit v1.2.3 From 2937ab9e320ea04fdfda8e3a252559d4762e811e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 31 Oct 2017 19:47:12 +0100 Subject: QHeaderView: Skip hidden sections on cascading resize When a section is hidden, QHeaderViewPrivate::cascadingResize() does resize a section even it is hidden. This leads to space between the neighbor sections and also some unneeded calculations. Task-number: QTBUG-54601 Change-Id: Ie139417ae2c77ef25e66cf628bfe400185f88ee8 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qheaderview.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 3af191b06c..298270a785 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3539,6 +3539,8 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize) // cascade the section size change for (int i = visual + 1; i < sectionCount(); ++i) { + if (isVisualIndexHidden(i)) + continue; if (!sectionIsCascadable(i)) continue; int currentSectionSize = headerSectionSize(i); @@ -3581,6 +3583,8 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize) // cascade the section size change if (delta < 0 && newSize < minimumSize) { for (int i = visual - 1; i >= 0; --i) { + if (isVisualIndexHidden(i)) + continue; if (!sectionIsCascadable(i)) continue; int sectionSize = headerSectionSize(i); @@ -3595,6 +3599,8 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize) // let the next section get the space from the resized section if (!sectionResized) { for (int i = visual + 1; i < sectionCount(); ++i) { + if (isVisualIndexHidden(i)) + continue; if (!sectionIsCascadable(i)) continue; int currentSectionSize = headerSectionSize(i); -- cgit v1.2.3 From c3aa422df6e3eb4af7bd75c7255586e9e5f79197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 6 Nov 2017 15:18:14 +0100 Subject: QWidget: Propagate window file path after create MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-63340 Change-Id: Ic21964a33ee2910200627fe8a8c8ec2454e2e20c Reviewed-by: Morten Johan Sørvig --- src/widgets/kernel/qwidget.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 9b6c3df828..de734b6f51 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1372,6 +1372,8 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) d->setWindowIconText_helper(d->topData()->iconText); if (isWindow() && !d->topData()->caption.isEmpty()) d->setWindowTitle_helper(d->topData()->caption); + if (isWindow() && !d->topData()->filePath.isEmpty()) + d->setWindowFilePath_helper(d->topData()->filePath); if (windowType() != Qt::Desktop) { d->updateSystemBackground(); -- cgit v1.2.3 From b02bd4bbad9f80154307d06ad95a6f96c30858f0 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 15 Aug 2017 11:19:32 +0700 Subject: QMenuPrivate: Rearrange member variables This saves 32 bytes per instance on 64-bit macOS, from 888 down to 856 bytes. Change-Id: I2592631aa3566d2eab72bad338aacfe76bee8ef3 Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qmenu_p.h | 129 +++++++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 53 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 4b7ce05169..8adfc82ef5 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -92,18 +92,18 @@ class QMenuSloppyState public: QMenuSloppyState() : m_menu(Q_NULLPTR) + , m_reset_action(Q_NULLPTR) + , m_origin_action(Q_NULLPTR) + , m_parent(Q_NULLPTR) + , m_uni_dir_discarded_count(0) + , m_uni_dir_fail_at_count(0) + , m_timeout(0) + , m_init_guard(false) + , m_first_mouse(true) , m_enabled(false) , m_uni_directional(false) , m_select_other_actions(false) - , m_first_mouse(true) - , m_init_guard(false) , m_use_reset_action(true) - , m_uni_dir_discarded_count(0) - , m_uni_dir_fail_at_count(0) - , m_timeout(0) - , m_reset_action(Q_NULLPTR) - , m_origin_action(Q_NULLPTR) - , m_parent(Q_NULLPTR) { } ~QMenuSloppyState() { reset(); } @@ -253,43 +253,59 @@ public: private: QMenu *m_menu; - bool m_enabled; - bool m_uni_directional; - bool m_select_other_actions; - bool m_first_mouse; - bool m_init_guard; - bool m_discard_state_when_entering_parent; - bool m_dont_start_time_on_leave; - bool m_use_reset_action; - short m_uni_dir_discarded_count; - short m_uni_dir_fail_at_count; - short m_timeout; - QBasicTimer m_time; QAction *m_reset_action; QAction *m_origin_action; QRectF m_action_rect; QPointF m_previous_point; QPointer m_sub_menu; QMenuSloppyState *m_parent; + QBasicTimer m_time; + short m_uni_dir_discarded_count; + short m_uni_dir_fail_at_count; + short m_timeout; + bool m_init_guard; + bool m_first_mouse; + + bool m_enabled : 1; + bool m_uni_directional : 1; + bool m_select_other_actions : 1; + bool m_discard_state_when_entering_parent : 1; + bool m_dont_start_time_on_leave : 1; + bool m_use_reset_action : 1; }; class QMenuPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMenu) public: - QMenuPrivate() : itemsDirty(0), maxIconWidth(0), tabWidth(0), ncols(0), - collapsibleSeparators(true), toolTipsVisible(false), - activationRecursionGuard(false), delayedPopupGuard(false), - hasReceievedEnter(false), - hasHadMouse(0), aboutToHide(0), motions(0), - currentAction(0), + QMenuPrivate() : + currentAction(nullptr), #ifdef QT_KEYPAD_NAVIGATION - selectAction(0), - cancelAction(0), + selectAction(nullptr), + cancelAction(nullptr), #endif - scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0), - hasCheckableItems(0), doChildEffects(false), platformMenu(0), - scrollUpTearOffItem(nullptr), scrollDownItem(nullptr) + scroll(nullptr), + eventLoop(nullptr), + platformMenu(nullptr), + scrollUpTearOffItem(nullptr), + scrollDownItem(nullptr), + maxIconWidth(0), + tabWidth(0), + motions(0), + activationRecursionGuard(false), + ncols(0), + itemsDirty(false), + hasCheckableItems(false), + collapsibleSeparators(true), + toolTipsVisible(false), + delayedPopupGuard(false), + hasReceievedEnter(false), + hasHadMouse(false), + aboutToHide(false), + tearoff(false), + tornoff(false), + tearoffHighlighted(false), + doChildEffects(false) { } ~QMenuPrivate() @@ -310,8 +326,6 @@ public: int scrollerHeight() const; //item calculations - mutable uint itemsDirty : 1; - mutable uint maxIconWidth, tabWidth; QRect actionRect(QAction *) const; mutable QVector actionRects; @@ -320,22 +334,12 @@ public: void updateActionRects(const QRect &screen) const; QRect popupGeometry() const; QRect popupGeometry(int screen) const; - mutable uint ncols : 4; //4 bits is probably plenty - uint collapsibleSeparators : 1; - uint toolTipsVisible : 1; int getLastVisibleAction() const; - bool activationRecursionGuard; - bool delayedPopupGuard; - bool hasReceievedEnter; - //selection static QMenu *mouseDown; QPoint mousePopupPos; - uint hasHadMouse : 1; - uint aboutToHide : 1; - int motions; - int mousePopupDelay; + QAction *currentAction; #ifdef QT_KEYPAD_NAVIGATION QAction *selectAction; @@ -365,8 +369,8 @@ public: } QMenu *parent; - QBasicTimer timer; QAction *action; + QBasicTimer timer; } delayState; enum SelectionReason { SelectedFromKeyboard, @@ -383,11 +387,12 @@ public: struct QMenuScroller { enum ScrollLocation { ScrollStay, ScrollBottom, ScrollTop, ScrollCenter }; enum ScrollDirection { ScrollNone=0, ScrollUp=0x01, ScrollDown=0x02 }; - uint scrollFlags : 2, scrollDirection : 2; int scrollOffset; QBasicTimer scrollTimer; + quint8 scrollFlags; + quint8 scrollDirection; - QMenuScroller() : scrollFlags(ScrollNone), scrollDirection(ScrollNone), scrollOffset(0) { } + QMenuScroller() : scrollOffset(0), scrollFlags(ScrollNone), scrollDirection(ScrollNone) { } ~QMenuScroller() { } } *scroll; void scrollMenu(QMenuScroller::ScrollLocation location, bool active=false); @@ -421,11 +426,8 @@ public: inline int indexOf(QAction *act) const { return q_func()->actions().indexOf(act); } //tear off support - uint tearoff : 1, tornoff : 1, tearoffHighlighted : 1; QPointer tornPopup; - mutable bool hasCheckableItems; - QMenuSloppyState sloppyState; //default action @@ -450,9 +452,6 @@ public: void adjustMenuScreen(const QPoint &p); void updateLayoutDirection(); - //menu fading/scrolling effects - bool doChildEffects; - QPointer platformMenu; QPointer actionAboutToTrigger; @@ -477,6 +476,30 @@ public: void drawScroller(QPainter *painter, ScrollerTearOffItem::Type type, const QRect &rect); void drawTearOff(QPainter *painter, const QRect &rect); QRect rect() const; + + mutable uint maxIconWidth, tabWidth; + int motions; + int mousePopupDelay; + + bool activationRecursionGuard; + + mutable quint8 ncols; // "255cols ought to be enough for anybody." + + mutable bool itemsDirty : 1; + mutable bool hasCheckableItems : 1; + bool collapsibleSeparators : 1; + bool toolTipsVisible : 1; + bool delayedPopupGuard : 1; + bool hasReceievedEnter : 1; + // Selection + bool hasHadMouse : 1; + bool aboutToHide : 1; + // Tear-off menus + bool tearoff : 1; + bool tornoff : 1; + bool tearoffHighlighted : 1; + //menu fading/scrolling effects + bool doChildEffects : 1; }; QT_END_NAMESPACE -- cgit v1.2.3 From 237b1c1d689fabf1680a8cf3d9226da5f712302d Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Sat, 26 Aug 2017 11:26:45 +0700 Subject: QMenuPrivate: Use in-class initializers where possible Change-Id: I5347cb41443baf96e28bd399c84983a801b10fcd Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qmenu_p.h | 87 +++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 56 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 8adfc82ef5..64d22087e3 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -91,16 +91,7 @@ class QMenuSloppyState Q_DISABLE_COPY(QMenuSloppyState) public: QMenuSloppyState() - : m_menu(Q_NULLPTR) - , m_reset_action(Q_NULLPTR) - , m_origin_action(Q_NULLPTR) - , m_parent(Q_NULLPTR) - , m_uni_dir_discarded_count(0) - , m_uni_dir_fail_at_count(0) - , m_timeout(0) - , m_init_guard(false) - , m_first_mouse(true) - , m_enabled(false) + : m_enabled(false) , m_uni_directional(false) , m_select_other_actions(false) , m_use_reset_action(true) @@ -252,19 +243,19 @@ public: QMenu *subMenu() const { return m_sub_menu; } private: - QMenu *m_menu; - QAction *m_reset_action; - QAction *m_origin_action; + QMenu *m_menu = nullptr; + QAction *m_reset_action = nullptr; + QAction *m_origin_action = nullptr; QRectF m_action_rect; QPointF m_previous_point; QPointer m_sub_menu; - QMenuSloppyState *m_parent; + QMenuSloppyState *m_parent = nullptr; QBasicTimer m_time; - short m_uni_dir_discarded_count; - short m_uni_dir_fail_at_count; - short m_timeout; - bool m_init_guard; - bool m_first_mouse; + short m_uni_dir_discarded_count = 0; + short m_uni_dir_fail_at_count = 0; + short m_timeout = 0; + bool m_init_guard = false; + bool m_first_mouse = true; bool m_enabled : 1; bool m_uni_directional : 1; @@ -279,21 +270,6 @@ class QMenuPrivate : public QWidgetPrivate Q_DECLARE_PUBLIC(QMenu) public: QMenuPrivate() : - currentAction(nullptr), -#ifdef QT_KEYPAD_NAVIGATION - selectAction(nullptr), - cancelAction(nullptr), -#endif - scroll(nullptr), - eventLoop(nullptr), - platformMenu(nullptr), - scrollUpTearOffItem(nullptr), - scrollDownItem(nullptr), - maxIconWidth(0), - tabWidth(0), - motions(0), - activationRecursionGuard(false), - ncols(0), itemsDirty(false), hasCheckableItems(false), collapsibleSeparators(true), @@ -340,15 +316,13 @@ public: static QMenu *mouseDown; QPoint mousePopupPos; - QAction *currentAction; + QAction *currentAction = nullptr; #ifdef QT_KEYPAD_NAVIGATION - QAction *selectAction; - QAction *cancelAction; + QAction *selectAction = nullptr; + QAction *cancelAction = nullptr; #endif struct DelayState { DelayState() - : parent(0) - , action(0) { } void initialize(QMenu *parent) { @@ -368,8 +342,8 @@ public: timer.stop(); } - QMenu *parent; - QAction *action; + QMenu *parent = nullptr; + QAction *action = nullptr; QBasicTimer timer; } delayState; enum SelectionReason { @@ -387,20 +361,20 @@ public: struct QMenuScroller { enum ScrollLocation { ScrollStay, ScrollBottom, ScrollTop, ScrollCenter }; enum ScrollDirection { ScrollNone=0, ScrollUp=0x01, ScrollDown=0x02 }; - int scrollOffset; + int scrollOffset = 0; QBasicTimer scrollTimer; - quint8 scrollFlags; - quint8 scrollDirection; + quint8 scrollFlags = ScrollNone; + quint8 scrollDirection = ScrollNone; - QMenuScroller() : scrollOffset(0), scrollFlags(ScrollNone), scrollDirection(ScrollNone) { } + QMenuScroller() { } ~QMenuScroller() { } - } *scroll; + } *scroll = nullptr; void scrollMenu(QMenuScroller::ScrollLocation location, bool active=false); void scrollMenu(QMenuScroller::ScrollDirection direction, bool page=false, bool active=false); void scrollMenu(QAction *action, QMenuScroller::ScrollLocation location, bool active=false); //synchronous operation (ie exec()) - QEventLoop *eventLoop; + QEventLoop *eventLoop = nullptr; QPointer syncAction; //search buffer @@ -433,8 +407,8 @@ public: //default action QPointer defaultAction; - QAction *menuAction; - QAction *defaultMenuAction; + QAction *menuAction = nullptr; + QAction *defaultMenuAction = nullptr; void setOverrideMenuAction(QAction *); void _q_overrideMenuActionDestroyed(); @@ -470,20 +444,21 @@ public: QMenuPrivate *menuPrivate; Type scrollType; }; - ScrollerTearOffItem *scrollUpTearOffItem; - ScrollerTearOffItem *scrollDownItem; + ScrollerTearOffItem *scrollUpTearOffItem = nullptr; + ScrollerTearOffItem *scrollDownItem = nullptr; void drawScroller(QPainter *painter, ScrollerTearOffItem::Type type, const QRect &rect); void drawTearOff(QPainter *painter, const QRect &rect); QRect rect() const; - mutable uint maxIconWidth, tabWidth; - int motions; - int mousePopupDelay; + mutable uint maxIconWidth = 0; + mutable uint tabWidth = 0; + int motions = 0; + int mousePopupDelay = 0; - bool activationRecursionGuard; + bool activationRecursionGuard = false; - mutable quint8 ncols; // "255cols ought to be enough for anybody." + mutable quint8 ncols = 0; // "255cols ought to be enough for anybody." mutable bool itemsDirty : 1; mutable bool hasCheckableItems : 1; -- cgit v1.2.3 From 7986e1e2f0c88ea305dd8a842884908ed4724fd7 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 20 Oct 2017 18:12:17 +0700 Subject: QMenuBar: Update title on change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When one of the menubar actions changed, we would omit to update several properties on the platform menu, most notably its title. Manual tested with BigMenuCreator, where the sequence menu->addAction(action); // A-operation action->setMenu(submenu); // S-operation would result in an "Untitled" menubar item on macOS, and this regardless of when the submenu is populated. Change-Id: I43989f36f6bf3f0b7056310ac986c06f8e02f128 Reviewed-by: Dmitry Shachnev Reviewed-by: Erik Verbruggen Reviewed-by: Morten Johan Sørvig --- src/widgets/widgets/qmenubar.cpp | 54 +++++++++++++++++++++++----------------- src/widgets/widgets/qmenubar_p.h | 4 ++- 2 files changed, 34 insertions(+), 24 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 41b6bf49f8..6dfbb7c8a1 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1187,7 +1187,7 @@ void QMenuBar::leaveEvent(QEvent *) d->setCurrentAction(0); } -QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action) +QPlatformMenu *QMenuBarPrivate::getPlatformMenu(const QAction *action) { if (!action || !action->menu()) return 0; @@ -1202,6 +1202,29 @@ QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action) return platformMenu; } +QPlatformMenu *QMenuBarPrivate::findInsertionPlatformMenu(const QAction *action) +{ + Q_Q(QMenuBar); + QPlatformMenu *beforeMenu = nullptr; + for (int beforeIndex = indexOf(const_cast(action)) + 1; + !beforeMenu && (beforeIndex < q->actions().size()); + ++beforeIndex) { + beforeMenu = getPlatformMenu(q->actions().at(beforeIndex)); + } + + return beforeMenu; +} + +void QMenuBarPrivate::copyActionToPlatformMenu(const QAction *action, QPlatformMenu *menu) +{ + const auto tag = reinterpret_cast(action); + if (menu->tag() != tag) + menu->setTag(tag); + menu->setText(action->text()); + menu->setVisible(action->isVisible()); + menu->setEnabled(action->isEnabled()); +} + /*! \reimp */ @@ -1218,16 +1241,9 @@ void QMenuBar::actionEvent(QActionEvent *e) if (e->type() == QEvent::ActionAdded) { QPlatformMenu *menu = d->getPlatformMenu(e->action()); if (menu) { - QPlatformMenu* beforeMenu = NULL; - for (int beforeIndex = d->indexOf(e->action()) + 1; - !beforeMenu && (beforeIndex < actions().size()); - ++beforeIndex) - { - beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); - } + d->copyActionToPlatformMenu(e->action(), menu); - menu->setTag(reinterpret_cast(e->action())); - menu->setText(e->action()->text()); + QPlatformMenu *beforeMenu = d->findInsertionPlatformMenu(e->action()); d->platformMenuBar->insertMenu(menu, beforeMenu); } } else if (e->type() == QEvent::ActionRemoved) { @@ -1235,7 +1251,7 @@ void QMenuBar::actionEvent(QActionEvent *e) if (menu) d->platformMenuBar->removeMenu(menu); } else if (e->type() == QEvent::ActionChanged) { - QPlatformMenu* cur = d->platformMenuBar->menuForTag(reinterpret_cast(e->action())); + QPlatformMenu *cur = d->platformMenuBar->menuForTag(reinterpret_cast(e->action())); QPlatformMenu *menu = d->getPlatformMenu(e->action()); // the menu associated with the action can change, need to @@ -1244,21 +1260,13 @@ void QMenuBar::actionEvent(QActionEvent *e) if (cur) d->platformMenuBar->removeMenu(cur); if (menu) { - menu->setTag(reinterpret_cast(e->action())); - - QPlatformMenu* beforeMenu = NULL; - for (int beforeIndex = d->indexOf(e->action()) + 1; - !beforeMenu && (beforeIndex < actions().size()); - ++beforeIndex) - { - beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); - } + d->copyActionToPlatformMenu(e->action(), menu); + + QPlatformMenu *beforeMenu = d->findInsertionPlatformMenu(e->action()); d->platformMenuBar->insertMenu(menu, beforeMenu); } } else if (menu) { - menu->setText(e->action()->text()); - menu->setVisible(e->action()->isVisible()); - menu->setEnabled(e->action()->isEnabled()); + d->copyActionToPlatformMenu(e->action(), menu); d->platformMenuBar->syncMenu(menu); } } diff --git a/src/widgets/widgets/qmenubar_p.h b/src/widgets/widgets/qmenubar_p.h index 01d8793a3a..c276a4512d 100644 --- a/src/widgets/widgets/qmenubar_p.h +++ b/src/widgets/widgets/qmenubar_p.h @@ -132,7 +132,9 @@ public: QBasicTimer autoReleaseTimer; QPlatformMenuBar *platformMenuBar; - QPlatformMenu *getPlatformMenu(QAction *action); + QPlatformMenu *getPlatformMenu(const QAction *action); + QPlatformMenu *findInsertionPlatformMenu(const QAction *action); + void copyActionToPlatformMenu(const QAction *e, QPlatformMenu *menu); inline int indexOf(QAction *act) const { return q_func()->actions().indexOf(act); } }; -- cgit v1.2.3 From 5d6878f234d1d8697bba43cb5140094dee722a86 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 24 Oct 2017 14:53:31 +0700 Subject: QMainWindow: Clear menubar parent when new one is set In QMainWindow::setMenuBar(), we hide and schedule the current menubar, if any, to be deleted later. However, it remains installed as its whole ancestry's event filter, which could conflict with the newly assigned menubar until the old menubar is destroyed. In our case, we have noticed issues with the Cocoa QPA plugin. We force uninstalling the old menubar as event filter by setting its parent to null, pending its deletion shortly after. This fixes BigMenuCreator's empty menubar when calling it with only the "--new-menubar" option. It also fixes QTBUG-34160 example which was not behaving as well as it should. Task-number: QTBUG-34160 Change-Id: Ifefb72affad01e7b7371005442074afd6a39a5b8 Reviewed-by: Dmitry Shachnev Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qmainwindow.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index 5c6f983149..ced7ec38ea 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -574,6 +574,7 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar) menuBar->setCornerWidget(cornerWidget, Qt::TopRightCorner); } oldMenuBar->hide(); + oldMenuBar->setParent(nullptr); oldMenuBar->deleteLater(); } topLayout->setMenuBar(menuBar); -- cgit v1.2.3 From 7465329fe18315d50c4e6325cfd7c9fc1e203812 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 25 Oct 2017 13:24:49 +0200 Subject: QAbstractButton: don't clear 'pressed' flag unless left button is released As it stood, we would set 'pressed' to false regardless of which button that was released. This would end up wrong if pressing the left button, and at the same time, did a click with the right button. This would clear the flag prematurely, and cause a release signal not to be emitted when later releasing the left button. tst_QAbstractButton: adding autotest Adding tests to simulate the bug report's cases: 1) left press button 2) click right/middle key 3) move mouse out of button's boundary 4) test if the released() signal triggered properly Taks-number: QTBUG-53244 Change-Id: Ifc0d5f52a917ac9cd2df5e86c0475abcda47e425 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qabstractbutton.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp index dbd94e890d..5854472ff0 100644 --- a/src/widgets/widgets/qabstractbutton.cpp +++ b/src/widgets/widgets/qabstractbutton.cpp @@ -991,13 +991,14 @@ void QAbstractButton::mousePressEvent(QMouseEvent *e) void QAbstractButton::mouseReleaseEvent(QMouseEvent *e) { Q_D(QAbstractButton); - d->pressed = false; if (e->button() != Qt::LeftButton) { e->ignore(); return; } + d->pressed = false; + if (!d->down) { // refresh is required by QMacStyle to resume the default button animation d->refresh(); -- cgit v1.2.3 From c8a5f331c8fdbf243ccb467f7bc3c9f62bd47c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20Szczygie=C5=82?= Date: Sun, 12 Nov 2017 18:54:04 +0100 Subject: QMenu: Update menu action sizes if popup is (not)caused from menu bar Menu width differs if it contains key shortcuts or not. Amends 6634c424f8ca0e3aed2898507d5f9f4b774c4602 Task-number: QTBUG-49435 Task-number: QTBUG-61181 Task-number: QTBUG-64449 Change-Id: I8c479af550128069ca91dd089dfc7bd8c24c66ba Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmenu.cpp | 6 ++++++ src/widgets/widgets/qmenu_p.h | 2 ++ 2 files changed, 8 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index ded218de73..463254efa9 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2339,6 +2339,12 @@ void QMenu::popup(const QPoint &p, QAction *atAction) d->updateLayoutDirection(); d->adjustMenuScreen(p); + const bool contextMenu = d->isContextMenu(); + if (d->lastContextMenu != contextMenu) { + d->itemsDirty = true; + d->lastContextMenu = contextMenu; + } + #if QT_CONFIG(menubar) // if this menu is part of a chain attached to a QMenuBar, set the // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index bdf576b980..a81d8ffafb 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -272,6 +272,7 @@ public: QMenuPrivate() : itemsDirty(false), hasCheckableItems(false), + lastContextMenu(false), collapsibleSeparators(true), toolTipsVisible(false), delayedPopupGuard(false), @@ -464,6 +465,7 @@ public: mutable bool itemsDirty : 1; mutable bool hasCheckableItems : 1; + bool lastContextMenu : 1; bool collapsibleSeparators : 1; bool toolTipsVisible : 1; bool delayedPopupGuard : 1; -- cgit v1.2.3 From 26986276531b7f0a3f950d4b3960d5302010d204 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 19 Oct 2017 15:35:25 +0700 Subject: QMenu: Refactor insertion of action in QPA menu First, remove a bit of code duplication around the creation of the platform menu item. Then, we move copyActionToPlatformItem() inside QMenuPrivate to get rid of one parameter. Change-Id: I5a33103566367f2313930479844365e79773d82f Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmenu.cpp | 108 +++++++++++++++++++++--------------------- src/widgets/widgets/qmenu_p.h | 3 ++ 2 files changed, 57 insertions(+), 54 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 463254efa9..c5b912e35b 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -234,9 +234,6 @@ void QMenuPrivate::setPlatformMenu(QPlatformMenu *menu) } } -// forward declare function -static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item, QPlatformMenu *itemsMenu); - void QMenuPrivate::syncPlatformMenu() { Q_Q(QMenu); @@ -246,19 +243,64 @@ void QMenuPrivate::syncPlatformMenu() QPlatformMenuItem *beforeItem = Q_NULLPTR; const QList actions = q->actions(); for (QList::const_reverse_iterator it = actions.rbegin(), end = actions.rend(); it != end; ++it) { - QPlatformMenuItem *menuItem = platformMenu->createMenuItem(); - QAction *action = *it; - menuItem->setTag(reinterpret_cast(action)); - QObject::connect(menuItem, SIGNAL(activated()), action, SLOT(trigger()), Qt::QueuedConnection); - QObject::connect(menuItem, SIGNAL(hovered()), action, SIGNAL(hovered()), Qt::QueuedConnection); - copyActionToPlatformItem(action, menuItem, platformMenu.data()); - platformMenu->insertMenuItem(menuItem, beforeItem); + QPlatformMenuItem *menuItem = insertActionInPlatformMenu(*it, beforeItem); beforeItem = menuItem; } platformMenu->syncSeparatorsCollapsible(collapsibleSeparators); platformMenu->setEnabled(q->isEnabled()); } +void QMenuPrivate::copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item) +{ + item->setText(action->text()); + item->setIsSeparator(action->isSeparator()); + if (action->isIconVisibleInMenu()) { + item->setIcon(action->icon()); + if (QWidget *w = action->parentWidget()) { + QStyleOption opt; + opt.init(w); + item->setIconSize(w->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, w)); + } else { + QStyleOption opt; + item->setIconSize(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, 0)); + } + } else { + item->setIcon(QIcon()); + } + item->setVisible(action->isVisible()); +#if QT_CONFIG(shortcut) + item->setShortcut(action->shortcut()); +#endif + item->setCheckable(action->isCheckable()); + item->setChecked(action->isChecked()); + item->setHasExclusiveGroup(action->actionGroup() && action->actionGroup()->isExclusive()); + item->setFont(action->font()); + item->setRole((QPlatformMenuItem::MenuRole) action->menuRole()); + item->setEnabled(action->isEnabled()); + + if (action->menu()) { + if (!action->menu()->platformMenu()) + action->menu()->setPlatformMenu(platformMenu->createSubMenu()); + item->setMenu(action->menu()->platformMenu()); + } else { + item->setMenu(0); + } +} + +QPlatformMenuItem * QMenuPrivate::insertActionInPlatformMenu(const QAction *action, QPlatformMenuItem *beforeItem) +{ + QPlatformMenuItem *menuItem = platformMenu->createMenuItem(); + Q_ASSERT(menuItem); + + menuItem->setTag(reinterpret_cast(action)); + QObject::connect(menuItem, &QPlatformMenuItem::activated, action, &QAction::trigger, Qt::QueuedConnection); + QObject::connect(menuItem, &QPlatformMenuItem::hovered, action, &QAction::hovered, Qt::QueuedConnection); + copyActionToPlatformItem(action, menuItem); + platformMenu->insertMenuItem(menuItem, beforeItem); + + return menuItem; +} + int QMenuPrivate::scrollerHeight() const { Q_Q(const QMenu); @@ -3483,43 +3525,6 @@ QMenu::timerEvent(QTimerEvent *e) } } -static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item, QPlatformMenu *itemsMenu) -{ - item->setText(action->text()); - item->setIsSeparator(action->isSeparator()); - if (action->isIconVisibleInMenu()) { - item->setIcon(action->icon()); - if (QWidget *w = action->parentWidget()) { - QStyleOption opt; - opt.init(w); - item->setIconSize(w->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, w)); - } else { - QStyleOption opt; - item->setIconSize(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, 0)); - } - } else { - item->setIcon(QIcon()); - } - item->setVisible(action->isVisible()); -#ifndef QT_NO_SHORTCUT - item->setShortcut(action->shortcut()); -#endif - item->setCheckable(action->isCheckable()); - item->setChecked(action->isChecked()); - item->setHasExclusiveGroup(action->actionGroup() && action->actionGroup()->isExclusive()); - item->setFont(action->font()); - item->setRole((QPlatformMenuItem::MenuRole) action->menuRole()); - item->setEnabled(action->isEnabled()); - - if (action->menu()) { - if (!action->menu()->platformMenu()) - action->menu()->setPlatformMenu(itemsMenu->createSubMenu()); - item->setMenu(action->menu()->platformMenu()); - } else { - item->setMenu(0); - } -} - /*! \reimp */ @@ -3573,15 +3578,10 @@ void QMenu::actionEvent(QActionEvent *e) if (!d->platformMenu.isNull()) { if (e->type() == QEvent::ActionAdded) { - QPlatformMenuItem *menuItem = d->platformMenu->createMenuItem(); - menuItem->setTag(reinterpret_cast(e->action())); - QObject::connect(menuItem, SIGNAL(activated()), e->action(), SLOT(trigger())); - QObject::connect(menuItem, SIGNAL(hovered()), e->action(), SIGNAL(hovered())); - copyActionToPlatformItem(e->action(), menuItem, d->platformMenu); QPlatformMenuItem *beforeItem = e->before() ? d->platformMenu->menuItemForTag(reinterpret_cast(e->before())) : nullptr; - d->platformMenu->insertMenuItem(menuItem, beforeItem); + d->insertActionInPlatformMenu(e->action(), beforeItem); } else if (e->type() == QEvent::ActionRemoved) { QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast(e->action())); d->platformMenu->removeMenuItem(menuItem); @@ -3589,7 +3589,7 @@ void QMenu::actionEvent(QActionEvent *e) } else if (e->type() == QEvent::ActionChanged) { QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast(e->action())); if (menuItem) { - copyActionToPlatformItem(e->action(), menuItem, d->platformMenu); + d->copyActionToPlatformItem(e->action(), menuItem); d->platformMenu->syncMenuItem(menuItem); } } diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index a81d8ffafb..ce5134958e 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -295,6 +295,9 @@ public: QPlatformMenu *createPlatformMenu(); void setPlatformMenu(QPlatformMenu *menu); void syncPlatformMenu(); + void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item); + QPlatformMenuItem *insertActionInPlatformMenu(const QAction *action, QPlatformMenuItem *beforeItem); + #ifdef Q_OS_OSX void moveWidgetToPlatformItem(QWidget *w, QPlatformMenuItem* item); #endif -- cgit v1.2.3