From f3ccc74a56e121ad0bbe0985f5e295dfd8070e57 Mon Sep 17 00:00:00 2001 From: Matthew Griffin <45285214+matthew-griffin@users.noreply.github.com> Date: Wed, 12 Jun 2019 12:45:08 +0100 Subject: [PATCH 1/3] Ensure that wxListCtrl::HitTest finds correct index under qt --- samples/listctrl/listtest.cpp | 9 ++++++--- samples/listctrl/listtest.h | 2 +- src/qt/listctrl.cpp | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 6ce7a10cb0..1e2ef5a6b4 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -1515,7 +1515,8 @@ void MyListCtrl::OnContextMenu(wxContextMenuEvent& event) { point = ScreenToClient(point); } - ShowContextMenu(point); + int flags; + ShowContextMenu(point, HitTest(point, flags)); } else { @@ -1527,10 +1528,12 @@ void MyListCtrl::OnContextMenu(wxContextMenuEvent& event) } #endif -void MyListCtrl::ShowContextMenu(const wxPoint& pos) +void MyListCtrl::ShowContextMenu(const wxPoint& pos, long item) { wxMenu menu; - + wxString itemNumber; + itemNumber.Printf("Item %ld", item); + menu.Append(wxID_ANY, itemNumber); menu.Append(wxID_ABOUT, "&About"); menu.AppendSeparator(); menu.Append(wxID_EXIT, "E&xit"); diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index dcdca2a55c..f20cdff66c 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -78,7 +78,7 @@ public: virtual bool IsItemChecked(long item) const wxOVERRIDE; private: - void ShowContextMenu(const wxPoint& pos); + void ShowContextMenu(const wxPoint& pos, long item); wxLog *m_logOld; void SetColumnImage(int col, int image); diff --git a/src/qt/listctrl.cpp b/src/qt/listctrl.cpp index 587961d3da..ca5f4e7457 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -910,7 +910,11 @@ long wxListCtrl::FindItem(long WXUNUSED(start), const wxPoint& WXUNUSED(pt), int long wxListCtrl::HitTest(const wxPoint& point, int &flags, long* ptrSubItem) const { - QModelIndex index = m_qtTreeWidget->indexAt(wxQtConvertPoint(point)); + // Remove the header height as qt expects point relative to the table sub widget + QPoint qPoint = wxQtConvertPoint(point); + qPoint.setY(qPoint.y() - m_qtTreeWidget->header()->height()); + + QModelIndex index = m_qtTreeWidget->indexAt(qPoint); if ( index.isValid() ) { flags = wxLIST_HITTEST_ONITEM; From e3f35e1082bd197b6df63a0436ced9e370f79e62 Mon Sep 17 00:00:00 2001 From: Matthew Griffin <45285214+matthew-griffin@users.noreply.github.com> Date: Thu, 13 Jun 2019 10:55:02 +0100 Subject: [PATCH 2/3] Ensure that rects from wxListCtrl are also offset by the header height --- src/qt/listctrl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/listctrl.cpp b/src/qt/listctrl.cpp index ca5f4e7457..6ccb693c33 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -595,6 +595,7 @@ bool wxListCtrl::GetItemRect(long item, wxRect& rect, int WXUNUSED(code)) const if ( qitem != NULL ) { rect = wxQtConvertRect( m_qtTreeWidget->visualItemRect(qitem) ); + rect.Offset(0, m_qtTreeWidget->header()->height()); return true; } else @@ -612,6 +613,7 @@ bool wxListCtrl::GetSubItemRect(long item, long subItem, wxRect& rect, int WXUNU wxT("invalid column index in GetSubItemRect") ); QModelIndex qindex = m_qtTreeWidget->model()->index(item, subItem); rect = wxQtConvertRect( m_qtTreeWidget->visualRect(qindex) ); + rect.Offset(0, m_qtTreeWidget->header()->height()); return true; } else From 2780f1bde648567fddfefa5183f9432f56438740 Mon Sep 17 00:00:00 2001 From: Matthew Griffin <45285214+matthew-griffin@users.noreply.github.com> Date: Mon, 2 Sep 2019 10:47:39 +0100 Subject: [PATCH 3/3] Added function to protect against null header when getting its height --- src/qt/listctrl.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/qt/listctrl.cpp b/src/qt/listctrl.cpp index 6ccb693c33..01a503b039 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -141,6 +141,11 @@ public: return m_editorFactory.GetEditControl(); } + int GetHeaderHeight() const + { + return header() != NULL ? header()->height() : 0; + } + private: void itemClicked(QTreeWidgetItem * item, int column); void itemActivated(QTreeWidgetItem * item, int column); @@ -595,7 +600,7 @@ bool wxListCtrl::GetItemRect(long item, wxRect& rect, int WXUNUSED(code)) const if ( qitem != NULL ) { rect = wxQtConvertRect( m_qtTreeWidget->visualItemRect(qitem) ); - rect.Offset(0, m_qtTreeWidget->header()->height()); + rect.Offset(0, m_qtTreeWidget->GetHeaderHeight()); return true; } else @@ -613,7 +618,7 @@ bool wxListCtrl::GetSubItemRect(long item, long subItem, wxRect& rect, int WXUNU wxT("invalid column index in GetSubItemRect") ); QModelIndex qindex = m_qtTreeWidget->model()->index(item, subItem); rect = wxQtConvertRect( m_qtTreeWidget->visualRect(qindex) ); - rect.Offset(0, m_qtTreeWidget->header()->height()); + rect.Offset(0, m_qtTreeWidget->GetHeaderHeight()); return true; } else @@ -914,7 +919,7 @@ long wxListCtrl::HitTest(const wxPoint& point, int &flags, long* ptrSubItem) con { // Remove the header height as qt expects point relative to the table sub widget QPoint qPoint = wxQtConvertPoint(point); - qPoint.setY(qPoint.y() - m_qtTreeWidget->header()->height()); + qPoint.setY(qPoint.y() - m_qtTreeWidget->GetHeaderHeight()); QModelIndex index = m_qtTreeWidget->indexAt(qPoint); if ( index.isValid() )