Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT: resizing a UI element with the mouse

Is there the possibility to enable the built-in resize capability from the Qt designer in my program ?

I've a Qt UI element with implementation, which I added to a QGraphicsView. Now I want to resize it like in my UI-Editor. How can I enable this ?

like image 234
schwenk Avatar asked Sep 15 '25 14:09

schwenk


2 Answers

You can use QSizeGrip in a layout inside your widget. This is a little hackis but is simple to implement :

myWidget->setWindowFlags(Qt::SubWindow);

QSizeGrip * sizeGrip = new QSizeGrip(myWidget);

QGridLayout * layout = new QGridLayout(myWidget);
layout->addWidget(sizeGrip, 0,0,1,1,Qt::AlignBottom | Qt::AlignRight);

The QSizeGrip class provides a resize handle for resizing top-level windows. When you set the widget flag Qt::SubWindow, then the user can resize it using the size grip.

like image 181
Nejat Avatar answered Sep 18 '25 08:09

Nejat


Another possibility is to use QSplitters. It is a method to organize graphic elements in a layout with a drag-able zone in between.

The use of splitters are explained here, also have a look on this question.

like image 36
and-bri Avatar answered Sep 18 '25 10:09

and-bri