Search code examples
qtqt-designerqdockwidget

QDockWidget form in Qt Creator Designer


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

  1. In the Projects tree on the left, right click on the project and select "Add New..."
  2. In the window that pops up select "Qt" on the left side, then select "Qt Designer Form Class", then select "Choose"
  3. On this page expand the section for "Widgets", then select "QDockWidget", then select "Next"
  4. On this page give the class a name (for me it's "ImageFilesDockWidget"), then click "Next"
  5. On this page select "Finish" to add the files to the project.
  6. 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.


Solution

  • 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.