Merge branch 'qt_list_ctrl_hit_test_offset' of https://github.com/GeoTeric/wxWidgets into qt-listctrl
Fix wxListCtrl::HitTest() which was off roughly by 1 due to not taking into account the header height. Closes https://github.com/wxWidgets/wxWidgets/pull/1350
This commit is contained in:
@@ -1543,7 +1543,8 @@ void MyListCtrl::OnContextMenu(wxContextMenuEvent& event)
|
|||||||
{
|
{
|
||||||
point = ScreenToClient(point);
|
point = ScreenToClient(point);
|
||||||
}
|
}
|
||||||
ShowContextMenu(point);
|
int flags;
|
||||||
|
ShowContextMenu(point, HitTest(point, flags));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1555,10 +1556,10 @@ void MyListCtrl::OnContextMenu(wxContextMenuEvent& event)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void MyListCtrl::ShowContextMenu(const wxPoint& pos)
|
void MyListCtrl::ShowContextMenu(const wxPoint& pos, long item)
|
||||||
{
|
{
|
||||||
wxMenu menu;
|
wxMenu menu;
|
||||||
|
menu.Append(wxID_ANY, wxString::Format("Menu for item %ld", item));
|
||||||
menu.Append(wxID_ABOUT, "&About");
|
menu.Append(wxID_ABOUT, "&About");
|
||||||
menu.AppendSeparator();
|
menu.AppendSeparator();
|
||||||
menu.Append(wxID_EXIT, "E&xit");
|
menu.Append(wxID_EXIT, "E&xit");
|
||||||
|
@@ -78,7 +78,7 @@ public:
|
|||||||
virtual bool IsItemChecked(long item) const wxOVERRIDE;
|
virtual bool IsItemChecked(long item) const wxOVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ShowContextMenu(const wxPoint& pos);
|
void ShowContextMenu(const wxPoint& pos, long item);
|
||||||
wxLog *m_logOld;
|
wxLog *m_logOld;
|
||||||
void SetColumnImage(int col, int image);
|
void SetColumnImage(int col, int image);
|
||||||
|
|
||||||
|
@@ -978,6 +978,11 @@ public:
|
|||||||
QTreeView::paintEvent(event);
|
QTreeView::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetHeaderHeight() const
|
||||||
|
{
|
||||||
|
return header() != NULL ? header()->height() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void itemClicked(const QModelIndex &index);
|
void itemClicked(const QModelIndex &index);
|
||||||
void itemActivated(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 first = m_qtTreeWidget->visualRect(m_model->index(item, 0));
|
||||||
QRect last = m_qtTreeWidget->visualRect(m_model->index(item, columnCount-1));
|
QRect last = m_qtTreeWidget->visualRect(m_model->index(item, columnCount-1));
|
||||||
rect = wxQtConvertRect(first.united(last));
|
rect = wxQtConvertRect(first.united(last));
|
||||||
|
rect.Offset(0, m_qtTreeWidget->GetHeaderHeight());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1336,6 +1342,7 @@ bool wxListCtrl::GetSubItemRect(long item,
|
|||||||
|
|
||||||
const QModelIndex index = m_qtTreeWidget->model()->index(item, subItem);
|
const QModelIndex index = m_qtTreeWidget->model()->index(item, subItem);
|
||||||
rect = wxQtConvertRect(m_qtTreeWidget->visualRect(index));
|
rect = wxQtConvertRect(m_qtTreeWidget->visualRect(index));
|
||||||
|
rect.Offset(0, m_qtTreeWidget->GetHeaderHeight());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1735,7 +1742,11 @@ long wxListCtrl::HitTest(
|
|||||||
long* ptrSubItem
|
long* ptrSubItem
|
||||||
) const
|
) 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() )
|
if ( index.isValid() )
|
||||||
{
|
{
|
||||||
flags = wxLIST_HITTEST_ONITEM;
|
flags = wxLIST_HITTEST_ONITEM;
|
||||||
|
Reference in New Issue
Block a user