From 23da60a23590c31417737b325eec18ca590f25a0 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Wed, 30 Apr 2025 14:13:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=9A=E8=BF=87=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=8E=A7=E4=BB=B6=E7=BC=96=E8=BE=91=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E4=BF=A1=E6=81=AF=E5=90=8Etableview=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E7=84=A6=E7=82=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/attributeTableDelegate.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/attributeTableDelegate.cpp b/source/attributeTableDelegate.cpp index 23f4101..3c7c284 100644 --- a/source/attributeTableDelegate.cpp +++ b/source/attributeTableDelegate.cpp @@ -198,10 +198,14 @@ QWidget* AttributeTableDelegate::createEditor(QWidget *parent, const QStyleOptio //判断放在setModelData函数中,因为那里会先进行是否做内容改变的判断 emit const_cast(this)->commitData(textEditor); emit const_cast(this)->closeEditor(textEditor, QAbstractItemDelegate::NoHint); + if(m_tableView) + m_tableView->setFocus(); }); connect(textEditor, &TextEditWidget::cancle, this, [=]{ //createEditor为const成员函数,而closeEditor是QAbstractItemDelegate的非const信号,在const成员函数中不能直接调用,需要转换为非const指针 emit const_cast(this)->closeEditor(textEditor, QAbstractItemDelegate::NoHint); + if(m_tableView) + m_tableView->setFocus(); }); //延迟获取焦点,防止可能因渲染未完成失效 QTimer::singleShot(10, this, [textEditor]() { @@ -215,9 +219,13 @@ QWidget* AttributeTableDelegate::createEditor(QWidget *parent, const QStyleOptio connect(textEditor, &TextEditWidget::confirm, this, [=]{ emit const_cast(this)->commitData(textEditor); emit const_cast(this)->closeEditor(textEditor, QAbstractItemDelegate::NoHint); + if(m_tableView) + m_tableView->setFocus(); }); connect(textEditor, &TextEditWidget::cancle, this, [=]{ emit const_cast(this)->closeEditor(textEditor, QAbstractItemDelegate::NoHint); + if(m_tableView) + m_tableView->setFocus(); }); //延迟获取焦点,防止可能因渲染未完成失效 QTimer::singleShot(10, this, [textEditor]() {