QWidget on top of other QWidget
-
Hello all,
I am trying to create the following design on Qt.

https://s27.postimg.org/knqu9zvyr/capture.png
Mainly I want to place a QWidget on top of another. What's the best way of doing it? There are few links online explaining this process and none of them worked.
Thanks,
-
Image upload doesn't work, please use an external service, see https://forum.qt.io/topic/62615/how-to-insert-image-on-this-forum
-
Image upload doesn't work, please use an external service, see https://forum.qt.io/topic/62615/how-to-insert-image-on-this-forum
-
Hello all,
I am trying to create the following design on Qt.

https://s27.postimg.org/knqu9zvyr/capture.png
Mainly I want to place a QWidget on top of another. What's the best way of doing it? There are few links online explaining this process and none of them worked.
Thanks,
hi,
thats simple enough, here's a short example:QWidget *widget1 = new QWidget(); widget1->setObjectName("w1"); widget1->resize(200,200); ... QWidget * widget2 = new QWidget(widget1); widget2->resize(100,100); widget2->setObjectName("w2"); widget2->move(50,50); ... widget1->setStyleSheet(QWidget#w1{background-color:red;}" QWidget#w2{background-color:blue;}"); widget1->show();this creates a blue widgets on top of a red one.
-
-
hi,
thats simple enough, here's a short example:QWidget *widget1 = new QWidget(); widget1->setObjectName("w1"); widget1->resize(200,200); ... QWidget * widget2 = new QWidget(widget1); widget2->resize(100,100); widget2->setObjectName("w2"); widget2->move(50,50); ... widget1->setStyleSheet(QWidget#w1{background-color:red;}" QWidget#w2{background-color:blue;}"); widget1->show();this creates a blue widgets on top of a red one.
-
@J.Hilk That just shows the colors, what if i had buttons inside the QWidget, can i still control these? Thank you for helping out!
sure its possible, every widget can have multiple children of its own.
You can either create and handle that all by yourself - that however might get quickly become complex and complicated - Or You use the tools Qt- provides for this, Like
QLayouts,QStackedWidgets,QTabWidgetsetc.Qt comes with
QtDesignermade to help you create a basic design via drag and drop.But I recommend @VRonin 's link that should get you started and help you understand the basics of creating a Ui by code.