6

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.

Stanton
  • 904
  • 10
  • 25

1 Answers1

15

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.

Scott S
  • 166
  • 1
  • 3
  • 1
    That solved it for me. Just to clarify for others who come across this, the line should actually be added just below ``. I was a little confused by your wording as you said to put it below the "windowTitle", which would place it inside of a section, which didn't work for me – Stanton Jan 10 '18 at 16:37
  • I see your confusion. When I said under, I meant under the end tag of the windowTitle property, not inside it. Thanks for the clarification. – Scott S Feb 07 '18 at 18:14
  • This still happens under Qt 5.13, do you know whether there is a bug report for this already? – codeling Oct 11 '19 at 12:48
  • I'm not sure. I didn't put an issue in for it. – Scott S Oct 15 '19 at 13:08