Add selectable & moveable *.ui-dialogues to QGraphicsScene[SOLVED]

  • Hello,
    I want to create with QT designer a variety of dialogues, which are to be added as selectable and moveable items in a QGraphicsScene. I'm not sure if and how it works, because the data types do not simply fit together. Does anyone know of a possible way?

    For my embedded system only QT 4.7.2 is Available.

  • I am currently trying to do something similar.

    So far:

    • I subclassed the QGraphicsProxyWidget class, which allows QWidget objects to be embedded in QGraphicsScene objects.
    • In the Proxy subclass constructor, build your QDialog and embed it in the Proxy with setWidget().
    • You can the simply add it to the scene with scene->addItem().

    Here's a sample of my Proxy widget constructor:

    @NodeItem::NodeItem(QGraphicsItem parent/, Qt::WindowFlags wflags*/)
    : QGraphicsProxyWidget(parent, Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint)
    setFlag(QGraphicsItem::ItemIsMovable, true);
    setFlag(QGraphicsItem::ItemIsSelectable, true);
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

    QDialog *m_nodeWidget = new QDialog();
    m_nodeWidget->setMinimumSize(100, 50);
    // Add widgets and layout to the dialog


    If you don't wish to add any extra graphics decorations to the dialog, you could directly subclass the QDialog class to create your dialogs and embed them in the QGraphicsScene with scene->addWidget(dlg) instead of addItem(). addWidget() automatically takes care of creating a Proxy for you.

  • Many thanks, works this way. I could the ui-dialog with
    // Add widgets and layout to the dialog
    Ui_DialDialog* pUi_DialDialog=new Ui_DialDialog();

    couple to m_nodeWidget.

    I was quite surprised that a QGraphicsProxyWidget with the addItem() function and not addWidget() must be inserted into a QGraphicsScene.

  • Yes, the QGraphicsProxyWidget's inheritance tree looks like this:

    QGraphicsItem -> QGraphicsObject -> QGraphicsWidget -> QGraphicsProxyWidget

    In the end, it is a QGraphicsItem objet, so it must be added with the addItem() function. The addWidget() function is reserved for QWidget objects, which are outside the Graphics Framework.

Log in to reply