将QGraphicsView和Qgraphicscene添加到Qt中的标签
我有一个堆叠的小部件,上面有一个QLabel。我在此标签上显示图像。我想缩放和平移这幅图像,我正在尝试使用QGraphicsView技术。但是,会打开一个新窗口。 这就是我正在做的将QGraphicsView和Qgraphicscene添加到Qt中的标签,qt,qgraphicsview,Qt,Qgraphicsview,我有一个堆叠的小部件,上面有一个QLabel。我在此标签上显示图像。我想缩放和平移这幅图像,我正在尝试使用QGraphicsView技术。但是,会打开一个新窗口。 这就是我正在做的 scene = new QGraphicsScene(this); view = new QGraphicsView(this); QPixmap pix("/root/Image); label->setPixmap(pix); scene->addWidget(label); view-&
scene = new QGraphicsScene(this);
view = new QGraphicsView(this);
QPixmap pix("/root/Image);
label->setPixmap(pix);
scene->addWidget(label);
view->setScene(scene);
view->setDragMode(QGraphicsView::scrollHandDrag);
view->show();
有人能建议我该怎么做吗。我希望标签像QGraphicsView一样工作
谢谢:)您创建了一个场景和视图,并将标签添加到场景中,然后告诉视图显示自己:-
view->show()
如您所述,如果希望在标签上显示QGraphicsView,请不要将标签添加到场景中,而是将QGraphicsView添加到标签中:-
QLabel* pLabel = new QLabel(mainWindow); // setting mainWindow as the parent
QGraphicsView* pView = new QGraphicsView(pLabel) // set the label as the parent of the view.
您不需要调用show,因为假设标签位于已显示的小部件上,标签将为您处理该问题
现在,不要在标签上设置pixmap,而是在场景中使用以下内容创建pixmap:-
pScene->addPixmap(pixmap);