[wxQt] Fix wxEVT_TREE_SEL_{CHANGING,CHANGED} generation/handling (PR #24600)

93 views
Skip to first unread message

AliKet

unread,
Jun 9, 2024, 4:08:49 PMJun 9
to wx-...@googlegroups.com, Subscribed

You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/24600

Commit Summary

  • 33a76a4 wxQt: Remove trailing white-space
  • 6cd9d69 wxQt: Simplify wxTreeCtrl::GetSelection() implementation
  • 2c8ca5c wxQt: Fix generating wxEVT_TREE_SEL_{CHANGING,CHANGED} events

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600@github.com>

VZ

unread,
Jun 9, 2024, 7:30:28 PMJun 9
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.

Thanks for the fixes, I think the logic is correct here, but if we could store the items in, say, wxQTreeWidget, as member variables, it would be better IMHO.


In src/qt/treectrl.cpp:

> +static wxTreeItemId gs_currentItem;
+static wxTreeItemId gs_previousItem;

Do these really need to be global? I am not 100% sure it's not going to be a problem, e.g. if a handler of some event changes selection in some other tree control.


In src/qt/treectrl.cpp:

> @@ -125,6 +125,61 @@ class ImageState
 
 Q_DECLARE_METATYPE(TreeItemDataQt)
 
+// We use a custom selection model because we need to generate the
+// wxEVT_TREE_SEL_CHANGED event only if it is allowed. that is, only

Nitpick of the day:

⬇️ Suggested change
-// wxEVT_TREE_SEL_CHANGED event only if it is allowed. that is, only
+// wxEVT_TREE_SEL_CHANGED event only if it is allowed, that is, only

(alternatively, keep the period, but capitalize "That")


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/review/2106397131@github.com>

AliKet

unread,
Jun 10, 2024, 4:33:48 PMJun 10
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • 73040e9 wxQt: Fix generating wxEVT_TREE_SEL_{CHANGING,CHANGED} events


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/2c8ca5c37013ce4e4961cd235ddfd367f504e1e3/after/73040e904beaf6aa0222141707084753f0b473a0@github.com>

AliKet

unread,
Jun 10, 2024, 4:35:33 PMJun 10
to wx-...@googlegroups.com, Subscribed

@AliKet commented on this pull request.


In src/qt/treectrl.cpp:

> @@ -125,6 +125,61 @@ class ImageState
 
 Q_DECLARE_METATYPE(TreeItemDataQt)
 
+// We use a custom selection model because we need to generate the
+// wxEVT_TREE_SEL_CHANGED event only if it is allowed. that is, only

forgot to update this


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/review/2108704396@github.com>

AliKet

unread,
Jun 10, 2024, 4:50:23 PMJun 10
to wx-...@googlegroups.com, Subscribed

@dsa-t It would be really apreciated if you could test this PR (or this patch) before it get merged because I had to change the implementation a little due to problems encountered with wxTreeBook control with the previous version.

TIA.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2159259663@github.com>

AliKet

unread,
Jun 10, 2024, 5:46:11 PMJun 10
to wx-...@googlegroups.com, Subscribed

Oops! this version reintroduced the infinite loop reported by @dsa-t which can be seen with the notebook sample (File -> Type -> Treebook)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2159342441@github.com>

AliKet

unread,
Jun 10, 2024, 6:13:31 PMJun 10
to wx-...@googlegroups.com, Subscribed

This is really strange because the treectrl sample works correctly but the notebook (treebook page) does not! maybe the problem is in the wxTreeBook control !?

Needs more debugging...


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2159396362@github.com>

AliKet

unread,
Jun 11, 2024, 2:24:14 PMJun 11
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • 80eb629 wxQt: Fix generating wxEVT_TREE_SEL_{CHANGING,CHANGED} events


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/73040e904beaf6aa0222141707084753f0b473a0/after/80eb629d035566ed515f40f15ff0f7d858ef9a54@github.com>

AliKet

unread,
Jun 11, 2024, 2:33:58 PMJun 11
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • a77fb17 wxQt: Fix generating wxEVT_TREE_SEL_{CHANGING,CHANGED} events


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/80eb629d035566ed515f40f15ff0f7d858ef9a54/after/a77fb17f293fc77c234b131de1e6f2f76d442dad@github.com>

AliKet

unread,
Jun 11, 2024, 2:36:28 PMJun 11
to wx-...@googlegroups.com, Subscribed

This is really strange because the treectrl sample works correctly but the notebook (treebook page) does not! maybe the problem is in the wxTreeBook control !?

Needs more debugging...

Everything seems to work correctly now: the treectrl and notebook (wxTreebook) samples.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2161382852@github.com>

dsa-t

unread,
Jun 14, 2024, 4:49:47 PMJun 14
to wx-...@googlegroups.com, Subscribed

Works good generally, but I also see a small issue with multiple selections:

  1. In wxTR_MULTIPLE mode, select File child 1.1 to File child 1.5
  2. Then, select, for example, File child 1.2
  3. Inside OnSelChanged, GetSelections will say "File child 1.1""File child 1.2""File child 1.3""File child 1.4""File child 1.5"
    Also the name editor gets triggered (I don't think it should).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2168744894@github.com>

AliKet

unread,
Jun 15, 2024, 1:59:56 PMJun 15
to wx-...@googlegroups.com, Subscribed

Works good generally, but I also see a small issue with multiple selections in treetest:

  1. In wxTR_MULTIPLE mode, select File child 1.1 to File child 1.5
  2. Then, select, for example, File child 1.2
  3. Inside OnSelChanged, GetSelections will say "File child 1.1""File child 1.2""File child 1.3""File child 1.4""File child 1.5"
    Also the name editor gets triggered (I don't think it should).

Thanks for testing, but it works correctly for me!

Screenshot.png (view on web)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2170426985@github.com>

dsa-t

unread,
Jun 15, 2024, 2:26:56 PMJun 15
to wx-...@googlegroups.com, Subscribed

Thanks for testing, but it works correctly for me!

In the 2nd step, I mean select just the 1.2 item, not deselect it:

image.png (view on web)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2170471987@github.com>

AliKet

unread,
Jun 15, 2024, 7:12:26 PMJun 15
to wx-...@googlegroups.com, Subscribed

Thanks for testing, but it works correctly for me!

In the 2nd step, I mean select just the 1.2 item, not deselect it:

Indeed, I can reproduce the problem. And the fix is simple which I'll push soon.
but preventing the editor from being triggered is trickier because this is how Qt interpret SelectedClicked flag passed here https://github.com/wxWidgets/wxWidgets/blob/f8043a62f3319719cbd3a400ea454e4dbb3d23ff/src/qt/treectrl.cpp#L1311-L1315

i.e. It starts editing when clicking on an already selected item

See Qt docs https://doc.qt.io/qt-6/qabstractitemview.html#EditTrigger-enum:~:text=QAbstractItemView%3A%3ASelectedClicked


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2170966199@github.com>

AliKet

unread,
Jun 16, 2024, 7:11:11 AMJun 16
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • 45d4dce wxQt: Fix generating wxEVT_TREE_SEL_{CHANGING,CHANGED} events


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/a77fb17f293fc77c234b131de1e6f2f76d442dad/after/45d4dce5c04a80da302d3f1e4131ba6568034c24@github.com>

AliKet

unread,
Jun 16, 2024, 8:50:44 AMJun 16
to wx-...@googlegroups.com, Subscribed

@dsa-t this patch:

diff --git a/src/qt/treectrl.cpp b/src/qt/treectrl.cpp
index ea68681ae0..45be7b0c48 100644
--- a/src/qt/treectrl.cpp
+++ b/src/qt/treectrl.cpp
@@ -330,11 +330,31 @@ protected:
         }
     }
 
+    // For compatibility with MSW, selecting an item that is part of a multiple selection
+    // simply deselects the other items without triggering the edit mode on the item. This
+    // is not the case with Qt because we already tell it to start editing when clicking
+    // on an already selected item with setEditTriggers(QTreeWidget::SelectedClicked) call.
+    bool m_blockEditing = false;
+
+    void selectionChanged(const QItemSelection& selected,
+                          const QItemSelection& deselected) override
+    {
+        m_blockEditing = selected.size() == 0;
+
+        QTreeView::selectionChanged(selected, deselected);
+    }
+
     bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) override
     {
         // AllEditTriggers means that editor is about to open, not waiting for double click
         if (trigger == AllEditTriggers)
         {
+            if ( m_blockEditing )
+            {
+                m_blockEditing = false;
+                return false;
+            }
+
             // Allow event handlers to veto opening the editor
             wxTreeEvent wx_event(
                 wxEVT_TREE_BEGIN_LABEL_EDIT,

solves the problem with starting edit you mention, but I'm still not sure if we should apply it or not because wxGTK3 also start editing if you do the following:

  • Select File child 1.1
  • Hold Ctrl key down and select File child 1.2
  • Now you have 2 item selected (File child 1.1 and File child 1.2)
  • Select File child 1.2 with or without holding the Ctrl key down.
  • The control starts editing the item.

Notice that this happens only if you select the focused item. wxMSW doesn't behave like this. i.e. it doesn't start editing at all.

@vadz any thoughts about this ?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2171575753@github.com>

VZ

unread,
Jun 18, 2024, 5:13:48 PMJun 18
to wx-...@googlegroups.com, Subscribed

I think wxGTK (i.e. generic implementation) is wrong here, this doesn't seem like a useful behaviour to me.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2176983843@github.com>

AliKet

unread,
Jun 23, 2024, 1:12:45 PM (12 days ago) Jun 23
to wx-...@googlegroups.com, Push

@AliKet pushed 6 commits.

  • 6bf265c Get rid of CppUnit boilerplate in wxTreeCtrl unit tests
  • 583e0a7 Put all WXUISIM_TEST under wxUSE_UIACTIONSIMULATOR in wxTreeCtrl unit tests
  • 22083d6 Test vetoing of wxEVT_TREE_SEL_CHANGING in wxTreeCtrl unit tests
  • 7a3133f Added SelectItemMultiInteractive test case to TreeCtrlTestCase
  • 7e2994e Fix unwanted item edit in wxQt wxTreeCtrl with wxTR_MULTIPLE
  • a658536 Fix unwanted item edit in wxGenericTreeCtrl with wxTR_MULTIPLE


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/45d4dce5c04a80da302d3f1e4131ba6568034c24/after/a658536f8c4f543237d2a68763d691611104e9c7@github.com>

AliKet

unread,
Jun 24, 2024, 6:23:14 PM (11 days ago) Jun 24
to wx-...@googlegroups.com, Push

@AliKet pushed 11 commits.

  • 0603834 wxQt: Remove trailing white-space
  • 3d61666 wxQt: respect wxTR_HIDE_ROOT style flag for wxTreeCtrl
  • e49038c wxQt: Simplify wxTreeCtrl::GetSelection() implementation
  • 6a54146 wxQt: Fix generating wxEVT_TREE_SEL_{CHANGING,CHANGED} events
  • b3302f1 Get rid of CppUnit boilerplate in wxTreeCtrl unit tests
  • 4a5642a Put all WXUISIM_TEST under wxUSE_UIACTIONSIMULATOR in wxTreeCtrl unit tests
  • b70e88f Test vetoing of wxEVT_TREE_SEL_CHANGING in wxTreeCtrl unit tests
  • 1844af0 Added SelectItemMultiInteractive test case to TreeCtrlTestCase
  • dda9ecd Fix unwanted item edit in wxQt wxTreeCtrl with wxTR_MULTIPLE
  • d891e7b Fix unwanted item edit in wxGenericTreeCtrl with wxTR_MULTIPLE
  • 81bebe0 Fix TreeCtrlTestCase failing under wxMSW after recent changes


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/a658536f8c4f543237d2a68763d691611104e9c7/after/81bebe0f4ad330853b6640904e2543d19ca60aab@github.com>

AliKet

unread,
Jun 24, 2024, 6:34:57 PM (11 days ago) Jun 24
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • 41e80cb Fix TreeCtrlTestCase failing under wxMSW after recent changes


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/81bebe0f4ad330853b6640904e2543d19ca60aab/after/41e80cbc1dd3a4071017052f482725c84847b053@github.com>

AliKet

unread,
Jun 25, 2024, 4:39:03 PM (10 days ago) Jun 25
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • 2de5654 Fix TreeCtrlTestCase failing under wxMSW after recent changes


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/41e80cbc1dd3a4071017052f482725c84847b053/after/2de56549c777777dfadb177704334c7a06e500bb@github.com>

AliKet

unread,
Jun 28, 2024, 10:03:56 AM (7 days ago) Jun 28
to wx-...@googlegroups.com, Subscribed

@vadz I have no idea what's going on here, or what to do with these failures?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2197006605@github.com>

VZ

unread,
Jun 28, 2024, 10:59:30 AM (7 days ago) Jun 28
to wx-...@googlegroups.com, Subscribed

I'm afraid that at least the Mac failures are real ones, i.e. actually due to the changes here as they seem to be occurring in the affected code. For the MSW ones I'm less sure and I don't have time to debug this right now, sorry...


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/c2197130015@github.com>

AliKet

unread,
Jun 28, 2024, 12:08:46 PM (7 days ago) Jun 28
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • c39f309 Temporarily disable the recently added test


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/2de56549c777777dfadb177704334c7a06e500bb/after/c39f30932e6aff227cc04b2cdf6302c965edf596@github.com>

AliKet

unread,
Jun 28, 2024, 2:11:48 PM (7 days ago) Jun 28
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • d643c81 Temporarily disable wxTreeCtrl::SelectionChange testtoo


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/c39f30932e6aff227cc04b2cdf6302c965edf596/after/d643c81cf4eaebae8911cd3af5065e28f25af6d4@github.com>

AliKet

unread,
Jun 28, 2024, 2:20:07 PM (7 days ago) Jun 28
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • d05dbfb Temporarily disable wxTreeCtrl::SelectionChange testtoo


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/d643c81cf4eaebae8911cd3af5065e28f25af6d4/after/d05dbfbfc26a1f7d86375b4c0376a37feef030c0@github.com>

AliKet

unread,
Jun 29, 2024, 3:37:32 PM (6 days ago) Jun 29
to wx-...@googlegroups.com, Push

@AliKet pushed 1 commit.

  • 6925e20 Temporarily disable wxTreeCtrl::SelectionChange test too

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/d05dbfbfc26a1f7d86375b4c0376a37feef030c0/after/6925e20eec2dccf24ec167adf11091ad91d77a4b@github.com>

AliKet

unread,
Jul 2, 2024, 3:06:52 PM (3 days ago) Jul 2
to wx-...@googlegroups.com, Push

@AliKet pushed 3 commits.

  • 00f5022 Added SelectItemMultiInteractive test case to TreeCtrlTestCase
  • 2c08bc0 Fix unwanted item edit in wxQt wxTreeCtrl with wxTR_MULTIPLE
  • 3b3b126 Fix unwanted item edit in wxGenericTreeCtrl with wxTR_MULTIPLE

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/6925e20eec2dccf24ec167adf11091ad91d77a4b/after/3b3b1264633451fb8e447ef8026b7698100a9519@github.com>

AliKet

unread,
Jul 4, 2024, 7:10:39 PM (14 hours ago) Jul 4
to wx-...@googlegroups.com, Push

@AliKet pushed 6 commits.

  • 3840b6b Get rid of CppUnit boilerplate in wxTreeCtrl unit tests
  • 4fb6244 Put all WXUISIM_TEST under wxUSE_UIACTIONSIMULATOR in wxTreeCtrl unit tests
  • 2a99c57 Test vetoing of wxEVT_TREE_SEL_CHANGING in wxTreeCtrl unit tests
  • 28a5434 Added SelectItemMultiInteractive test case to TreeCtrlTestCase
  • bb32ea3 Fix unwanted item edit in wxQt wxTreeCtrl with wxTR_MULTIPLE
  • dd60c9c Fix unwanted item edit in wxGenericTreeCtrl with wxTR_MULTIPLE

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/3b3b1264633451fb8e447ef8026b7698100a9519/after/dd60c9ccea1637ee22845e0eac8c23ab7e8e6f32@github.com>

AliKet

unread,
Jul 4, 2024, 7:59:26 PM (13 hours ago) Jul 4
to wx-...@googlegroups.com, Push

@AliKet pushed 10 commits.

  • 42007fc wxQt: Remove trailing white-space
  • cff117b wxQt: respect wxTR_HIDE_ROOT style flag for wxTreeCtrl
  • 392729a wxQt: Simplify wxTreeCtrl::GetSelection() implementation
  • cd79f04 wxQt: Fix generating wxEVT_TREE_SEL_{CHANGING,CHANGED} events
  • cb80ec7 Get rid of CppUnit boilerplate in wxTreeCtrl unit tests
  • aa4b3b7 Put all WXUISIM_TEST under wxUSE_UIACTIONSIMULATOR in wxTreeCtrl unit tests
  • d80efc2 Test vetoing of wxEVT_TREE_SEL_CHANGING in wxTreeCtrl unit tests
  • 1afe3b9 Added SelectItemMultiInteractive test case to TreeCtrlTestCase
  • 2a46b3e Fix unwanted item edit in wxQt wxTreeCtrl with wxTR_MULTIPLE
  • 8741e64 Fix unwanted item edit in wxGenericTreeCtrl with wxTR_MULTIPLE

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24600/before/dd60c9ccea1637ee22845e0eac8c23ab7e8e6f32/after/8741e64b7ca25c90ed0b2ac9659b4c43d8530ef8@github.com>

Reply all
Reply to author
Forward
0 new messages