如何将QSizeGrip放置在QDial的右下方?

时间:2018-06-20 06:28:01

标签: c++ qt qt5 qgraphicsview qsizegrip

在GraphicsView(QGraphicsView)上,我设置了场景(QGraphicsScene),我正在通过qgraphicsproxy小部件添加qdial对象,将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);` 

输出图片

1 个答案:

答案 0 :(得分: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