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. Add selectable & moveable *.ui-dialogues to QGraphicsScene[SOLVED]
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.7k Views
  • 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.
  • R Offline
    R Offline
    R.B.
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Guigui
      wrote on last edited by
      #2

      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)
      {
      setCacheMode(DeviceCoordinateCache);
      setFlag(QGraphicsItem::ItemIsMovable, true);
      setFlag(QGraphicsItem::ItemIsSelectable, true);
      setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
      setZValue(0);

      QDialog *m_nodeWidget = new QDialog();
      m_nodeWidget->setWindowTitle(tr("Title"));
      m_nodeWidget->setMinimumSize(100, 50);
      
      // Add widgets and layout to the dialog
      (...)
      
      setWidget(m_nodeWidget);
      

      }@

      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.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        R.B.
        wrote on last edited by
        #3

        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();
        pUi_DialDialog->setupUi(m_nodeWidget);
        @

        couple to m_nodeWidget.

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Guigui
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

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