Open a QDialog in QStyledItemDelegate
-
Hello
I try to open a QDialog as an delegate. It works so far. But when the Delegate opens and I click first on the window (for resizing) the Dialog disappears.
Otherwise when one of the widgets within the dialog gets clicked first then it works as expected. Also to touch the window and resize works then.It would would be great if you could give me a reason for this behave and maybe a solution to fix that
Thanks in advanceHere a picture of my app and the delegate
The .cpp file:
include "delFilterEdit.h"
#include <QPainter>DelFilterEdit::DelFilterEdit(MdlOverViewFilter *model)
{
sourceModel = model;
}QWidget *DelFilterEdit::createEditor(QWidget *parent, const QStyleOptionViewItem & /option/, const QModelIndex &index) const
{
auto dlg = new DlgFilterEdit{sourceModel, index, parent};
dlg->setModal(true);
dlg->setWindowTitle("FilterEdit: " + sourceModel->headerData(index.column(), Qt::Orientation::Horizontal, Qt::DisplayRole).toString());
return dlg;}
void DelFilterEdit::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (DlgFilterEdit *dlg = static_cast <DlgFilterEdit *> (editor)) {
dlg->setEditorData(index);
}
}void DelFilterEdit::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (DlgFilterEdit *dlg = qobject_cast <DlgFilterEdit *> (editor)) {
model->setData(index, dlg->getFld(), Qt::EditRole);
}
}
hope someone can give my hint about problem. -
Hello
I try to open a QDialog as an delegate. It works so far. But when the Delegate opens and I click first on the window (for resizing) the Dialog disappears.
Otherwise when one of the widgets within the dialog gets clicked first then it works as expected. Also to touch the window and resize works then.It would would be great if you could give me a reason for this behave and maybe a solution to fix that
Thanks in advanceHere a picture of my app and the delegate
The .cpp file:
include "delFilterEdit.h"
#include <QPainter>DelFilterEdit::DelFilterEdit(MdlOverViewFilter *model)
{
sourceModel = model;
}QWidget *DelFilterEdit::createEditor(QWidget *parent, const QStyleOptionViewItem & /option/, const QModelIndex &index) const
{
auto dlg = new DlgFilterEdit{sourceModel, index, parent};
dlg->setModal(true);
dlg->setWindowTitle("FilterEdit: " + sourceModel->headerData(index.column(), Qt::Orientation::Horizontal, Qt::DisplayRole).toString());
return dlg;}
void DelFilterEdit::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (DlgFilterEdit *dlg = static_cast <DlgFilterEdit *> (editor)) {
dlg->setEditorData(index);
}
}void DelFilterEdit::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (DlgFilterEdit *dlg = qobject_cast <DlgFilterEdit *> (editor)) {
model->setData(index, dlg->getFld(), Qt::EditRole);
}
}
hope someone can give my hint about problem.@QTom said in Open a QDialog in QStyledItemDelegate:
But when the Delegate opens and I click first on the window (for resizing) the Dialog disappears.
I assume it has to do with the window decoration and the way the delegate handles its "editor widget".
But I don't have a solution to fix it -
Hi,
Which version of Qt ?
On which OS ?
If Linux:- which distribution ?
- which desktop environment ?
- which window manager ?
-
Hi,
Which version of Qt ?
On which OS ?
If Linux:- which distribution ?
- which desktop environment ?
- which window manager ?
-
@SGaist said in Open a QDialog in QStyledItemDelegate:
:
Hello
as requested my environment:
Product: Qt Creator 17.0.0
Based on: Qt 6.9.1 (GCC 10.3.1 20210422 (Red Hat 10.3.1-1), x86_64)
Built on: Jun 17 2025 16:12:20
From revision: 4983f08c47@QTom said in Open a QDialog in QStyledItemDelegate:
Based on: Qt 6.9.1 (GCC 10.3.1 20210422 (Red Hat 10.3.1-1), x86_64)
This does not say anything about the Qt version you're using.
-
@QTom said in Open a QDialog in QStyledItemDelegate:
Based on: Qt 6.9.1 (GCC 10.3.1 20210422 (Red Hat 10.3.1-1), x86_64)
This does not say anything about the Qt version you're using.
-
It happens because the QDialog loses focus when clicking on the window frame first. Try setting setModal(true) or setWindowModality(Qt::ApplicationModal), and use activateWindow() after show() to keep it active🙂.
-
It happens because the QDialog loses focus when clicking on the window frame first. Try setting setModal(true) or setWindowModality(Qt::ApplicationModal), and use activateWindow() after show() to keep it active🙂.
Hi Thank you for the hint,
the setModal(true) and setWindowModality(Qt::ApplicationModal) has no effect.the activateWindow() where do you mean I should locate it?
If I see it right, the opening of the editor is done in the QAbstractItemView.Do you have a sample which fixes this issue?