Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 在QGraphicsView上绘制小部件(如按钮)_Qt_Qgraphicsview_Qgraphicsitem - Fatal编程技术网

Qt 在QGraphicsView上绘制小部件(如按钮)

Qt 在QGraphicsView上绘制小部件(如按钮),qt,qgraphicsview,qgraphicsitem,Qt,Qgraphicsview,Qgraphicsitem,如何在QGraphicsView上绘制交互小部件,如QButtons和线条编辑? 例如,我在图像编辑应用程序中选择了图像上方的区域,该应用程序使用QGraphicsView显示图像,我想用名称注释该区域 所以我想在这个矩形选择下面有一个线条编辑和两个按钮(十字和勾号)。 我怎么画这些 示例代码将很酷 您可以像添加任何其他控件一样添加这些控件。我使用Qt的设计器生成以下内容: class MyForm: public QMainWindow { private: QGrap

如何在QGraphicsView上绘制交互小部件,如QButtons和线条编辑? 例如,我在图像编辑应用程序中选择了图像上方的区域,该应用程序使用QGraphicsView显示图像,我想用名称注释该区域

所以我想在这个矩形选择下面有一个线条编辑和两个按钮(十字和勾号)。 我怎么画这些


示例代码将很酷

您可以像添加任何其他控件一样添加这些控件。我使用Qt的设计器生成以下内容:

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));
        }
};

qgraphicscene
有一个函数
addWidget()
,您可以在其中向场景添加小部件。如果不想使用scene addWidget函数,可以创建一个
QGraphicsProxyWidget
使用
setWidget()
并将代理小部件添加到场景中。

谢谢,这就是我想要的。@Phlip没有布局,只有几何体。sez“将进度条添加为QWidget的子项,而不将其添加到布局中。”Tx-如果这意味着对象->添加子项(x)或类似内容可用。我现在几乎没有任何桌面上的Qt项目;经济繁荣的迫切性。