Multiple widgets on a QDockWidget
Asked Answered
B

1

7

I'm making a little app for applying various filters on an image using Qt and C++.

My question is, is it possible to add multiple widgets on a QDockWidget ? As i want to add buttons for re-applying the last 5 filters on the dock.

Here is an example of what i want to achieve.

Exemple of what i want to achieve

Balkanize answered 9/10, 2014 at 11:4 Comment(0)
A
12

It is possible add to multiple QWidgets into any QWidget. It looks like you probably want to do something like this:

QDockWidget dock(QLatin1String("Last filters"));
QWidget* multiWidget = new QWidget();
QVBoxLayout* layout = new QVBoxLayout();
QPushButton* filter1 = new QPushButton(QLatin1String("Filter number 1"));
QPushButton* filter2 = new QPushButton(QLatin1String("Filter number 2"));
QPushButton* filter3 = new QPushButton(QLatin1String("Filter number 3"));
QPushButton* filter4 = new QPushButton(QLatin1String("Filter number 4"));
QPushButton* filter5 = new QPushButton(QLatin1String("Filter number 5"));
QLabel* label = new QLabel(QLatin1String("QPushButtons"));

layout->addWidget(filter1);
layout->addWidget(filter2);
layout->addWidget(filter3);
layout->addWidget(filter4);
layout->addWidget(filter5);
layout->addWidget(label);
multiWidget->setLayout(layout);
dock.setWidget(multiWidget);
Adena answered 9/10, 2014 at 11:41 Comment(4)
Can you provide the complete code for this example so that the example can be built from scratch?Kilohertz
@AvnerMoshkovitz I'm sorry, but no. That goes against the intention and purpose of stackoverflow.com If you have a question about how to do something I'd love to help; just ask a question and link me to it. Asking me to do something for you is quite different. This isn't a tutorial site or a prototype library. That said I would like to help. So I'd suggest starting here: doc.qt.io/qt-5/qtexamplesandtutorials.html If after attempting you're still struggling with getting something specific going, I'd say you're ready to ask a how question!Adena
It would be interesting to know whether a layout can be added directly to the dock widget. In this case multiWidget would not be required, only layout. It seems this is not possible, contrary to other Widget derived classes.Excerpta
While I think this answer is correct, the proposed method puts an unexpected and maybe unwanted padding around the added widgets. To get rid of this padding, use layout.setContentsMargins(0, 0, 0, 0).Sadick

© 2022 - 2024 — McMap. All rights reserved.