Taco de Wolff
Taco de Wolff

Reputation: 1758

Qt Designer; difficulty placing widgets in the right parent

Using the Qt Designer I've made a couple of QFrames in each other, each having a horizontal layout. Their stylesheet predicates that they should have no margin nor a padding. This means that in the Qt Designers view as well as in the final result, no space is seen between the QFrames.

Using drag-and-drop I can place widgets into the window, it shows a blue line where it will be placed (in a layout). However, it's impossible to add another QFrame to a QFrame parent I can't see (and thus drop on). There is also a tree in the right panel, but dropping on the parent makes it automatically go in one of the childs...

Example, I have this setup:

QMainWindow
- QWidget
  - QFrame (parent)
    - QFrame (child)
    - QFrame (child)

Adding a new frame, whatever I try, gives me:

QMainWindow
- QWidget
  - QFrame (parent)
    - QFrame (child)
    - QFrame (child)
    - QFrame (new child)

But I really want:

QMainWindow
- QWidget
  - QFrame (parent)
    - QFrame (child)
    - QFrame (child)
  - QFrame (new parent)

Is there any feature I haven't discovered to accurately place new widgets?

Upvotes: 12

Views: 16243

Answers (3)

RvdK
RvdK

Reputation: 19790

In Qt Creator 4.3 I also found it hard to drag an item into a layout which has no items yet.

Easiest way to get it working is to add the Layout to the form. Then drag your item from the Toolbox onto the layout in the Object Inspecter Window. Which will add the item into the Layout.

Unknown if this works for older for older versions of Qt Creator.

Upvotes: 1

Caleb Huitt - cjhuitt
Caleb Huitt - cjhuitt

Reputation: 14941

One workaround I've used is to select the widget I want to be adding to, add a margin to that widget's layout, drag and drop the widget, then remove the margin again. This way, at least I get it in the correct widget.

Upvotes: 9

jkerian
jkerian

Reputation: 17016

You can use the Object Inspector window, but you don't seem to be able to paste into a QFrame that has a locked layout.

So given your layout:

QMainWindow
- QWidget
  - QFrame (A)
    - QFrame (B)
    - QFrame (C)
    - QFrame (D)

Select QFrame D in the Object Inspector window and Cut it, right click QWidget and Break the layout (ctrl-0), then paste. Then re-apply the layout.

Upvotes: 6

Related Questions