Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Open a QDialog in QStyledItemDelegate
Forum Updated to NodeBB v4.3 + New Features

Open a QDialog in QStyledItemDelegate

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q QTom

    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 advance

    Here a picture of my app and the delegate
    Bildschirmfoto vom 2025-08-13 12-05-14.png

    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.

    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by Pl45m4
    #2

    @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


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi,

      Which version of Qt ?
      On which OS ?
      If Linux:

      • which distribution ?
      • which desktop environment ?
      • which window manager ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of Qt ?
        On which OS ?
        If Linux:

        • which distribution ?
        • which desktop environment ?
        • which window manager ?
        Q Offline
        Q Offline
        QTom
        wrote on last edited by
        #4

        @SGaist said in Open a QDialog in QStyledItemDelegate:

        :

        Hello

        as requested my environment:

        Bildschirmfoto vom 2025-08-14 07-18-14.png

        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

        jsulmJ 1 Reply Last reply
        0
        • Q QTom

          @SGaist said in Open a QDialog in QStyledItemDelegate:

          :

          Hello

          as requested my environment:

          Bildschirmfoto vom 2025-08-14 07-18-14.png

          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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply
          0
          • jsulmJ jsulm

            @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.

            Q Offline
            Q Offline
            QTom
            wrote on last edited by
            #6

            @jsulm

            Hello this I found.

            Bildschirmfoto vom 2025-08-14 09-23-53.png

            jsulmJ 1 Reply Last reply
            0
            • Q QTom

              @jsulm

              Hello this I found.

              Bildschirmfoto vom 2025-08-14 09-23-53.png

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @QTom Can't you simply check what Qt version is configured in the Kit you're using?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              Q 1 Reply Last reply
              0
              • jsulmJ jsulm

                @QTom Can't you simply check what Qt version is configured in the Kit you're using?

                Q Offline
                Q Offline
                QTom
                wrote on last edited by
                #8

                @jsulm
                Here it is

                Bildschirmfoto vom 2025-08-14 11-04-57.png

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jawadulhassan
                  wrote on last edited by jawadulhassan
                  #9

                  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🙂.

                  Q 1 Reply Last reply
                  0
                  • J jawadulhassan

                    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🙂.

                    Q Offline
                    Q Offline
                    QTom
                    wrote on last edited by
                    #10

                    @jawadulhassan

                    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?

                    Q 1 Reply Last reply
                    0
                    • Q QTom

                      @jawadulhassan

                      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?

                      Q Offline
                      Q Offline
                      QTom
                      wrote last edited by
                      #11

                      Hello again, it took a while to fix this behave.

                      Just to let you know

                      I added the command to the dialog on calling setEditorData
                      setFocusProxy(ui->editLine );

                      hope this helps also someone of you.

                      1 Reply Last reply
                      0
                      • Q QTom has marked this topic as solved

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved