Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 256
Stanton Avatar asked Dec 20 '17 20:12

Stanton


People also ask

How do you change geometry in Qt Designer?

You can override the defaults by clicking on the parent widget of the layout, and scrolling down to the bottom of the Property Editor, where you'll see a Layout section with the relevant values ( -1 means "use the default").

What is .UI file in Qt?

ui file is used to create a ui_calculatorform. h file that can be used by any file listed in the SOURCES declaration. Note: You can use Qt Creator to create the Calculator Form project. It automatically generates the main.


1 Answers

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.

like image 133
Scott S Avatar answered Sep 21 '22 03:09

Scott S