How to place QSizeGrip in the bottom right of a QDial?

705 Views Asked by At

On GraphicsView(QGraphicsView) i set scene(QGraphicsScene), i am adding qdial object throgh qgraphicsproxy widget, place sizegrip on bottom right position? `

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

image of output

1

There are 1 best solutions below

1
On BEST ANSWER

You have to use a layout as I show below:

#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