vcl/inc/qt5/QtTreeViewItemDelegate.hxx | 5 +++++ vcl/qt5/QtInstanceTreeView.cxx | 12 +++++++++++- vcl/qt5/QtTreeViewItemDelegate.cxx | 5 ++++- 3 files changed, 20 insertions(+), 2 deletions(-)
New commits: commit 2235539146d1f770c3fed24dc935a454e665685e Author: Michael Weghorn <[email protected]> AuthorDate: Fri Jan 23 02:07:05 2026 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Jan 23 10:41:43 2026 +0100 tdf#130857 qt weld: Implement QtInstanceTreeView::end_editing Remember the editor widget created in QtTreeViewItemDelegate::createEditor and pass it to QAbstractItemDelegate::closeEditor [1] when editing should be ended. Tested with the below additional local change in place and the following steps with the qt6 VCL plugin and SAL_VCL_QT_USE_WELDED_WIDGETS=1 : * start Writer * type "Hello world" * select the text * "Insert -> Bookmark" * confirm bookmark creation with "Insert" * "Insert" -> "Bookmark" * select the treeview entry * press the "Edit Text" button and start typing * move the mouse pointer over the treeview -> editing ends diff --git a/sw/source/ui/inc/bookmark.hxx b/sw/source/ui/inc/bookmark.hxx index 9901711ca551..d1064efb7ba4 100644 --- a/sw/source/ui/inc/bookmark.hxx +++ b/sw/source/ui/inc/bookmark.hxx @@ -39,6 +39,8 @@ public: sw::mark::MarkBase* GetBookmarkByName(const OUString& sName); OUString GetNameProposal() const; + DECL_LINK(MouseMoveHdl, const MouseEvent&, bool); + void unselect_all() { m_xControl->unselect_all(); } bool has_focus() const { return m_xControl->has_focus(); } std::unique_ptr<weld::TreeIter> get_selected() const; diff --git a/sw/source/ui/misc/bookmark.cxx b/sw/source/ui/misc/bookmark.cxx index ed01a2e030e3..fc458085faac 100644 --- a/sw/source/ui/misc/bookmark.cxx +++ b/sw/source/ui/misc/bookmark.cxx @@ -22,6 +22,7 @@ #include <sfx2/request.hxx> #include <svl/stritem.hxx> #include <unotools/viewoptions.hxx> +#include <vcl/event.hxx> #include <vcl/weld/weld.hxx> #include <o3tl/string_view.hxx> #include <com/sun/star/frame/XModel.hpp> @@ -496,6 +497,8 @@ BookmarkTable::BookmarkTable(std::unique_ptr<weld::TreeView> xControl) m_xControl->set_size_request(-1, m_xControl->get_height_rows(8)); m_xControl->set_column_fixed_widths({ 40, 110, 150, 160 }); m_xControl->set_selection_mode(SelectionMode::Multiple); + + m_xControl->connect_mouse_move(LINK(this, BookmarkTable, MouseMoveHdl)); } std::unique_ptr<weld::TreeIter> BookmarkTable::get_selected() const @@ -600,4 +603,11 @@ OUString BookmarkTable::GetNameProposal() const return sDefaultBookmarkName + " " + OUString::number(nHighestBookmarkId + 1); } +IMPL_LINK_NOARG(BookmarkTable, MouseMoveHdl, const MouseEvent&, bool) +{ + m_xControl->end_editing(); + + return false; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ [1] https://doc.qt.io/qt-6/qabstractitemdelegate.html#closeEditor Change-Id: Id69ac38b574650a38451b98565c3fc739a8813ea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197893 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtTreeViewItemDelegate.hxx b/vcl/inc/qt5/QtTreeViewItemDelegate.hxx index 60672cca7371..e6e8701bb4b6 100644 --- a/vcl/inc/qt5/QtTreeViewItemDelegate.hxx +++ b/vcl/inc/qt5/QtTreeViewItemDelegate.hxx @@ -9,6 +9,7 @@ #pragma once +#include <QtCore/QPointer> #include <QtWidgets/QStyledItemDelegate> #include <QtWidgets/QWidget> @@ -21,6 +22,8 @@ class QtTreeViewItemDelegate : public QStyledItemDelegate std::function<bool(const QModelIndex& rIndex, const QString& rNewText)> m_aFinishEditingFunction; + mutable QPointer<QWidget> m_pEditor; + public: QtTreeViewItemDelegate(QObject* pParent, std::function<bool(const QModelIndex& rIndex)> aStartEditingFunction, @@ -31,6 +34,8 @@ public: const QModelIndex& rIndex) const override; virtual void setModelData(QWidget* pEditor, QAbstractItemModel* pModel, const QModelIndex& rIndex) const override; + + void endEditing(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index b21fa119c4ef..9cd29b5e866d 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -573,7 +573,17 @@ void QtInstanceTreeView::start_editing(const weld::TreeIter& rEntry) }); } -void QtInstanceTreeView::end_editing() { assert(false && "Not implemented yet"); } +void QtInstanceTreeView::end_editing() +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + QtTreeViewItemDelegate* pDelegate + = qobject_cast<QtTreeViewItemDelegate*>(m_pTreeView->itemDelegate()); + assert(pDelegate); + pDelegate->endEditing(); + }); +} void QtInstanceTreeView::enable_drag_source(rtl::Reference<TransferDataContainer>&, sal_uInt8) { diff --git a/vcl/qt5/QtTreeViewItemDelegate.cxx b/vcl/qt5/QtTreeViewItemDelegate.cxx index e80944ee9aae..53ffff33a2af 100644 --- a/vcl/qt5/QtTreeViewItemDelegate.cxx +++ b/vcl/qt5/QtTreeViewItemDelegate.cxx @@ -27,7 +27,8 @@ QWidget* QtTreeViewItemDelegate::createEditor(QWidget* pParent, const QStyleOpti if (!m_aStartEditingFunction(rIndex)) return nullptr; - return QStyledItemDelegate::createEditor(pParent, rOption, rIndex); + m_pEditor = QStyledItemDelegate::createEditor(pParent, rOption, rIndex); + return m_pEditor; } void QtTreeViewItemDelegate::setModelData(QWidget* pEditor, QAbstractItemModel* pModel, @@ -43,4 +44,6 @@ void QtTreeViewItemDelegate::setModelData(QWidget* pEditor, QAbstractItemModel* QStyledItemDelegate::setModelData(pEditor, pModel, rIndex); } +void QtTreeViewItemDelegate::endEditing() { closeEditor(m_pEditor); } + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
