From 8efe01bd8e8751e0bc4b4a781a047380d6bde552 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Tue, 5 Feb 2019 13:46:32 +0000 Subject: [PATCH] Implement basic styles for wxTreeCtrl under wxQT --- include/wx/qt/treectrl.h | 2 ++ src/qt/treectrl.cpp | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/wx/qt/treectrl.h b/include/wx/qt/treectrl.h index 51ecd87ef8..88f503374c 100644 --- a/include/wx/qt/treectrl.h +++ b/include/wx/qt/treectrl.h @@ -112,6 +112,8 @@ public: virtual bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, bool textOnly = false) const wxOVERRIDE; + virtual void SetWindowStyleFlag(long styles) wxOVERRIDE; + virtual QWidget *GetHandle() const wxOVERRIDE; protected: diff --git a/src/qt/treectrl.cpp b/src/qt/treectrl.cpp index 1a8377799f..c701fb98df 100644 --- a/src/qt/treectrl.cpp +++ b/src/qt/treectrl.cpp @@ -71,6 +71,7 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& name) { m_qtTreeWidget = new wxQTreeWidget(parent, this); + SetWindowStyleFlag(style); return QtCreateControl(parent, id, pos, size, style, validator, name); } @@ -337,9 +338,7 @@ void wxTreeCtrl::SetFocusedItem(const wxTreeItemId& item) void wxTreeCtrl::ClearFocusedItem() { - QTreeWidgetItem *current = m_qtTreeWidget->currentItem(); - if (current != NULL) - current->setSelected(false); + m_qtTreeWidget->setCurrentItem(NULL); } wxTreeItemId wxTreeCtrl::GetFocusedItem() const @@ -622,11 +621,7 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select) { QList selections = m_qtTreeWidget->selectedItems(); const size_t nSelections = selections.size(); - - for (size_t i = 0; i < nSelections; ++i) - { - selections[i]->setSelected(false); - } + m_qtTreeWidget->clearSelection(); } QTreeWidgetItem *qTreeItem = wxQtConvertTreeItem(item); @@ -700,6 +695,13 @@ bool wxTreeCtrl::GetBoundingRect(const wxTreeItemId& item, wxRect& rect, bool te return false; } +void wxTreeCtrl::SetWindowStyleFlag(long styles) +{ + wxControl::SetWindowStyleFlag(styles); + m_qtTreeWidget->invisibleRootItem()->setHidden((styles & wxTR_HIDE_ROOT) != 0); + m_qtTreeWidget->setSelectionMode(styles & wxTR_MULTIPLE ? QTreeWidget::MultiSelection : QTreeWidget::SingleSelection); +} + int wxTreeCtrl::DoGetItemState(const wxTreeItemId& item) const { wxCHECK_MSG(item.IsOk(), wxTREE_ITEMSTATE_NONE, "invalid tree item");