Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] How to get a List Widget to expand with the Dock widget?
I dragged a dock widget into Qt designer, then dragged a list widget into the dock widget.
When I undock the dock widget and adjust the borders so it's larger, the list widget stays the same size and does not fill the dockwidget window. How do I make it fill the dock widget window?
You probably need to set the layout for the dock widget.
Oke, set the layout of the dockwidgetContents and your there.
I tried setting the layout of the dockwidgetContents in the mainwindow constructor using:
QVBoxLayout *lo = new QVBoxLayout();
but it didn't have any effect.
How do I set the layout of dockwidgetContents?
When I try to do it in the Qt Designer, the context menu for a vertical layout is greyed out.
I found the solution, but I need to affect the GUI outside the Qt Designer. Adding a layout to the dockContentsWidget of the dockWidget should be doable from within Qt Designer!!
I wrote the following in the mainwindow constructor and it worked well: (while mainly using Qt Designer, which won't let me add a layout to the dockContentsWidget via the context menu...or at least I can't find a way to do so)
MainWindow::MainWindow(QWidget *parent) :
QVBoxLayout *vertLayout = new QVBoxLayout; // wrote this
vertLayout->addWidget(ui->listWidget_2); // wrote this
ui->dockWidgetContents_2->setLayout(vertLayout); // wrote this
Your code is just what Designer would create for you. I must say that in Designer it's a bit stupid to set the layout, I agree with you there. It is possible though. On the right hand side in the Object inspector select the dockWidgetContents and the in the top of the screen select the desired layout. Must say it really is a bit unlogical! The same goes for TabWidget layouts etc, but when not encountered it before it is a real pain to find it on your own.
Sorry, that doesn't work.
Will get back to you on it!
Ahh, got it, forgot to mention you need some widgets on the dockWidget, then you can set the layout of the DockWidget. Got confused, sorry!
Let me begin by praising Qt and Qt Creator. What a great piece of software!
Having written the above, let me also point out that there are "many" little undocumented "quirks" in Qt Designer that really don't need to be there. Someone must work to improve the designer so "quirks" are nonexistent and usage is intuitive like the rest of Qt Creator.
Too many hours are "wasted" on "quirks" when the time would be better spent on development.
In many cases, solutions by helpers gravitate towards doing GUI work outside of Qt Designer. This is so prevalent that those who prefer using Qt Designer must explicitly state so to avoid more solutions that ignore the Designer. Even the examples are mostly not Qt Designer-centric.
To sidestep enormously accrued "quirks-solving" time, many acquiesce (like me) to a solution of writing GUI code in the mainwindow class that (as you pointed out) could have been easily done using the Designer, but not obvious.
If GUI-centric "faster-to-project-completion" alternatives were not present, the Designer would not be used at all.
There is suspicion that Qt Designer is not being avidly improved(like making the Designer more WYSIWYG[what you see is what you get]) due to Nokia's focus on Qt Quick for mobile platforms. Maybe Qt Quick is intended to eventually supplant Qt Designer altogether.
There should be a document that lists all the odd quirks of Qt Designer and their solutions as the user community discovers and solves them. This would be a great document.
I STILL LOVE Qt !!!