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;