Drawing widgets (such as buttons) over QGraphicsView

后端 未结 2 590
日久生厌
日久生厌 2021-01-06 23:43

How do I draw interactive widgets such as QButtons and Line Edits over a QGraphicsView? For ex, I have selected a region over an image in an image editing app which displays

相关标签:
2条回答
  • 2021-01-06 23:47

    You can just add these as you would do with any other control. I used Qt's Designer to generate the following:

    class MyForm: public QMainWindow
    {
        private:
            QGraphicsView *graphicsView;
            QLineEdit *lineEdit;
            QPushButton *pushButton;
            QPushButton *pushButton_2;
        public:
            MyForm() 
            {
                graphicsView = new QGraphicsView(this);
                graphicsView->setObjectName(QString::fromUtf8("graphicsView"));
                graphicsView->setGeometry(QRect(130, 90, 441, 191));
                lineEdit = new QLineEdit(graphicsView);
                lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
                lineEdit->setGeometry(QRect(160, 150, 113, 22));
                pushButton = new QPushButton(graphicsView);
                pushButton->setObjectName(QString::fromUtf8("pushButton"));
                pushButton->setGeometry(QRect(280, 140, 115, 32));
                pushButton_2 = new QPushButton(graphicsView);
                pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
                pushButton_2->setGeometry(QRect(400, 140, 115, 32));
            }
    };
    
    0 讨论(0)
  • 2021-01-06 23:57

    QGraphicsScene has a function addWidget() where you can add a widget to a scene. If you don't want to go through the scene addWidget function you can create a QGraphicsProxyWidget use setWidget() and add the proxy widget to your scene.

    0 讨论(0)
提交回复
热议问题