diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 80be50908b..5cc6cf6dd4 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -1543,7 +1543,8 @@ void MyListCtrl::OnContextMenu(wxContextMenuEvent& event) { point = ScreenToClient(point); } - ShowContextMenu(point); + int flags; + ShowContextMenu(point, HitTest(point, flags)); } else { @@ -1555,10 +1556,10 @@ void MyListCtrl::OnContextMenu(wxContextMenuEvent& event) } #endif -void MyListCtrl::ShowContextMenu(const wxPoint& pos) +void MyListCtrl::ShowContextMenu(const wxPoint& pos, long item) { wxMenu menu; - + menu.Append(wxID_ANY, wxString::Format("Menu for item %ld", item)); 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 fb1cfd5e7d..d44fec3b18 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 25b06889fc..8959517240 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -978,6 +978,11 @@ public: QTreeView::paintEvent(event); } + int GetHeaderHeight() const + { + return header() != NULL ? header()->height() : 0; + } + private: void itemClicked(const QModelIndex &index); void itemActivated(const QModelIndex &index); @@ -1319,6 +1324,7 @@ bool wxListCtrl::GetItemRect(long item, wxRect& rect, int WXUNUSED(code)) const QRect first = m_qtTreeWidget->visualRect(m_model->index(item, 0)); QRect last = m_qtTreeWidget->visualRect(m_model->index(item, columnCount-1)); rect = wxQtConvertRect(first.united(last)); + rect.Offset(0, m_qtTreeWidget->GetHeaderHeight()); return true; } @@ -1336,6 +1342,7 @@ bool wxListCtrl::GetSubItemRect(long item, const QModelIndex index = m_qtTreeWidget->model()->index(item, subItem); rect = wxQtConvertRect(m_qtTreeWidget->visualRect(index)); + rect.Offset(0, m_qtTreeWidget->GetHeaderHeight()); return true; } @@ -1735,7 +1742,11 @@ long wxListCtrl::HitTest( 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->GetHeaderHeight()); + + QModelIndex index = m_qtTreeWidget->indexAt(qPoint); if ( index.isValid() ) { flags = wxLIST_HITTEST_ONITEM;