如何将QSizeGrip放在QDial的右下角?

问题描述 投票:1回答:1

在GraphicsView(QGraphicsView)上我设置场景(QGraphicsScene),我正在添加qdial对象throgh qgraphicsproxy小部件,将sizegrip放在右下角位置? `

QDial *dial = new QDial(); //  dial object
plot->setGeometry(event->pos().x(),event->pos().y(),80,80);

QSizeGrip * sizeGrip = new QSizeGrip(dial );// placing sizegrip

QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget();
proxy->setWidget(dial );
proxy->setFlag(QGraphicsItem::ItemIsMovable,true);
scene->addItem(proxy);` 

输出图像

c++ qt qt5 qgraphicsview qsizegrip
1个回答
2
投票

您必须使用我在下面显示的布局:

#include <QApplication>
#include <QDial>
#include <QGraphicsProxyWidget>
#include <QGraphicsView>
#include <QHBoxLayout>
#include <QSizeGrip>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGraphicsView view;

    QGraphicsScene *scene = new QGraphicsScene(&view);
    view.setScene(scene);

    QDial *dial = new QDial;
    QSizeGrip * sizeGrip = new QSizeGrip(dial);

    QHBoxLayout *layout = new QHBoxLayout(dial);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(sizeGrip, 0, Qt::AlignRight | Qt::AlignBottom);

    QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget();
    proxy->setWidget(dial);
    proxy->setFlag(QGraphicsItem::ItemIsMovable,true);
    scene->addItem(proxy);

    view.show();
    return a.exec();
}

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.