QDockWidget form in Qt Creator Designer - qt

I'm using Qt Creator 4.5.0 and am trying to create a QDockWidget that I could modify in the builtin designer (I do this all the time with QDialogs and QMainWindows, so this is the first time trying with a QDockWidget). But I'm having no luck with being able to add any widget elements of any kind to the QDockWidget.
Here are the steps I've taken
In the Projects tree on the left, right click on the project and select "Add New..."
In the window that pops up select "Qt" on the left side, then select "Qt Designer Form Class", then select "Choose"
On this page expand the section for "Widgets", then select "QDockWidget", then select "Next"
On this page give the class a name (for me it's "ImageFilesDockWidget"), then click "Next"
On this page select "Finish" to add the files to the project.
From here the "ImageFilesDockWidget.ui" file will automatically show up, so I tried to add some widgets to the view, but nothing would get added. For example, if I clicked and dragged a pushbutton into the center of the dockwidget, then it displayed a red circle with a line through it to indicate I couldn't add the item.
If anyone has run into this problem and knows how to make it work, then that'd be an immense help to me.
Thanks in advance.
update
Currently I'm able to use the designer to customize a standard QWidget object (call it "ImageFilesWidget.ui"). So at the moment my solution is to add a standard QDockWidget to my QMainWindow in the designer, then (still in the designer) I promote the dockWidgetContents from a standard QWidget to my ImageFilesWidget class.

It seems like the problem is when qtcreator 4.5 creates the dockwidgets ui file for you, it doesn't include the "dockWidgetContents" widget that is included in previous versions. Just manually put <widget class="QWidget" name="dockWidgetContents"/> under the "windowTitle" property of the dockwidget and you'll be able to add ui elements to it.

Related

How to hide a widget created by QtDesigner "design" mode programmatically?

I want to know how to create a QLabel in QtCreator Design mode that is hidden by default?In the properties list in the right hand side panel , there's not any option regarding visibility and also adding label->hide() to setupUi function (after compiling ui file and adding to the project headers) makes no difference.
Designer doesn't expose the visible property. You could hand-edit the UI file, but that will be overwritten next time you edit in Designer. It's best to leave it visible in Designer, and just write a line of code after you call setupUi() to hide the widget you don't want to be initially shown.

Workaround Qt bug Combobox dropdown appear behind window

Right now I have a small tool app that runs in the icon tray. When I click on the icon, the app goes into "windowstayontophint" mode. I added a Combo Box on this window. But when I click elsewhere on desktop, and then click the combo box, the drop down window goes to the back of the window. This seems to be a known bug as reported here:
https://bugreports.qt.io/browse/QTBUG-61804
Is there a workaround for this? I am using Qt 5.9.1.
EDIT: Add some code:
This in MainWindow constructor:
Qt::WindowFlags flags = this->windowFlags();
this->setWindowFlags(flags|Qt::WindowStaysOnTopHint);
Then I put a QComboBox in the mainwindow with preloaded items. First time click, the dropdown appears on top as normal. Then I click onn desktop and then back on the mainwindow and combobox. And drop down becomes at the back of mainwindow. CLick on the link above to see what I mean. The bug report also provide screenshot of what is happening.
Nobody want to put an answer, so I answer this myself.
ANSWER: Update to latest Qt.
It did not work for me because I was having trouble updating (noob here). What basically happened was that Selecting "Update" option on Maintenance Tool does not update SDK from 5.9.1 to 5.10.1. It only update certain things like Qt Creator.
I needed to choose "Add or remove Components" and then adding Qt 5.10.1, but only check the MinGW 32bit only. (Uncheck all others otherwise you need them (like android or other)).
Even after that, you also need to manually download CMake (get it from cmake.com) and set it in "Manage Kits" in Qt Creator.

Qt: Tab Icon when QDockWidget becomes docked

Qt's QMainWindow has a ability to dock windows derived from QDockWidget. It also would put one on top on the other if few of them are stacked, producing a tab bar. Whenever a QDockWidget's state changes a signal topLevelChanged() is emmitted. At this point I would like to get access to underlying QTabWidget to set an icon for a a newly added tab. How can I do it? My patience is over trying to dig the answer out from Qt's documentation and source code. Thank you in advance.
So icon I want to be on Contents/Index tabs.
Once at least one dockwidget has been tabified, the main-window will create a QTabBar to provide the dock-tabs. Each dock-area can have its own tab-bar. These tab-bars will become children of the main-window, so you can use findChildren() or children() to get references to them.
The main difficulty will be in finding which dock-widget belongs to which tab and in which tab-bar. If the dock-widget window-titles are all unique, you can just search using the tabText(). Otherwise, you might be able to use the tabData(), which Qt sets internally to a quintptr from the dock-widget.
Once you have the correct tab, you can of course use setTabIcon() to add your icon. But note that every time a dock-widget is untabified or moved to another tab-bar, the icon will be lost.

Promoting a top level widget using Qt Designer

I am trying to promote the top level QWidget into a derived MyWidget class using the "promote to" menu in Qt Designer.
For that, i have defined the promotion with the "promoted widgets.." menu.
I have also add a child QWidget (in violet) to the top level QWidget and i was able to promote into it into MyWidget using the "promote to" option, that appear after a right click in the object inspector. (as shown in the picture)
But for the top level QWidget, the right click don't give access to the "promote to" menu and i have the same problem with a QFrame.
Is it possible to do that with Qt Designer ?
Thank you.
No, you can't promote top Widget in Designer. But you can do it manually. Simply open ui file in text editor and make necessary changes to the top level widget. Which changes you will need you can see in your child widget defenition. Just copypaste needed fields and values.

Initially hidden control in Qt Creator

I want to make a group box shown only when a radio button is selected.
I managed to do that by connecting the toggled(bool) signal of the radio button to the setShown(bool) slot of the group box.
The problem is that the radio button is initially deselected but the group box is initially shown so I have to select/deselect the radio button to make it disappear.
Is there any way I can make the group box initially invisible in Qt Creator Designer without having to do it in code?
You can't.
The visible property seems to be voluntarily removed from the property editor of Qt Designer and you can't add it back.
You can add the property manually to the .ui file by adding the following XML block inside the node for the widget you want to hide:
<property name="visible">
<bool>false</bool>
</property>
But the widget won't be visible or movable when you reopen the interface with the designer. It will still appear in the widget hierarchy though.
You can try playing round with the Properties (look at setHidden), but it's much easier to do it in the code.
So you'd do:
ui setup code
ui->groupBox->setHidden(true)
radio button slot
if true ui->groupBox->setHidden(false)
else if false ui->groupBox->setHidden(true)
That's the easiest way really, I've never had much luck with adding properties in Designer that Qt already uses.

Resources