完善上一个提交的问题
This commit is contained in:
parent
d791041e59
commit
7347ff578b
|
|
@ -31,7 +31,7 @@ signals:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject*, QEvent*) override;
|
bool eventFilter(QObject*, QEvent*) override;
|
||||||
//void closeEvent(QCloseEvent*) override;
|
//void mousePressEvent(QMouseEvent*) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTextChanged();
|
void onTextChanged();
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ TextEditWidget::TextEditWidget(QWidget* parent)
|
||||||
connect(ui->btnConfirm, &QPushButton::clicked, this, &TextEditWidget::onBtnClicked_confirm);
|
connect(ui->btnConfirm, &QPushButton::clicked, this, &TextEditWidget::onBtnClicked_confirm);
|
||||||
connect(ui->btnCancle, &QPushButton::clicked, this, &TextEditWidget::onBtnClicked_cancle);
|
connect(ui->btnCancle, &QPushButton::clicked, this, &TextEditWidget::onBtnClicked_cancle);
|
||||||
|
|
||||||
|
installEventFilter(this);
|
||||||
ui->plainTextEdit->installEventFilter(this);
|
ui->plainTextEdit->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,7 +35,9 @@ TextEditWidget::~TextEditWidget()
|
||||||
|
|
||||||
bool TextEditWidget::eventFilter(QObject* obj, QEvent* event)
|
bool TextEditWidget::eventFilter(QObject* obj, QEvent* event)
|
||||||
{
|
{
|
||||||
if (/*obj == this && */event->type() == QEvent::KeyPress)
|
if(obj == this && event->type() == QEvent::MouseButtonPress)
|
||||||
|
return true; //戒断鼠标事件,防止传递给父组件(tableView)触发单元格切换造成的editor关闭
|
||||||
|
else if (obj == ui->plainTextEdit && event->type() == QEvent::KeyPress)
|
||||||
{
|
{
|
||||||
QKeyEvent* pKeyEvent = static_cast<QKeyEvent*>(event);
|
QKeyEvent* pKeyEvent = static_cast<QKeyEvent*>(event);
|
||||||
if (pKeyEvent->key() == Qt::Key_Escape)
|
if (pKeyEvent->key() == Qt::Key_Escape)
|
||||||
|
|
@ -46,6 +49,11 @@ bool TextEditWidget::eventFilter(QObject* obj, QEvent* event)
|
||||||
return QWidget::eventFilter(obj, event);
|
return QWidget::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void TextEditWidget::mousePressEvent(QMouseEvent* event)
|
||||||
|
// {
|
||||||
|
// event->accept();
|
||||||
|
// }
|
||||||
|
|
||||||
QString TextEditWidget::editText()
|
QString TextEditWidget::editText()
|
||||||
{
|
{
|
||||||
return ui->plainTextEdit->toPlainText();
|
return ui->plainTextEdit->toPlainText();
|
||||||
|
|
@ -233,6 +241,10 @@ QWidget* AttributeTableDelegate::createEditor(QWidget *parent, const QStyleOptio
|
||||||
if(m_tableView)
|
if(m_tableView)
|
||||||
m_tableView->setFocus();
|
m_tableView->setFocus();
|
||||||
});
|
});
|
||||||
|
connect(textEditor, &TextEditWidget::closeWidget, this, [=]{
|
||||||
|
if(m_tableView)
|
||||||
|
m_tableView->setFocus();
|
||||||
|
});
|
||||||
//延迟获取焦点,防止可能因渲染未完成失效
|
//延迟获取焦点,防止可能因渲染未完成失效
|
||||||
QTimer::singleShot(10, this, [textEditor]() {
|
QTimer::singleShot(10, this, [textEditor]() {
|
||||||
textEditor->setFocusToTextEdit();
|
textEditor->setFocusToTextEdit();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue