59

I am using Qt Designer, and I would like to move a couple of top-level widgets into a horizontal layout.

I have dragged a "Horizontal Layout" object into the form. I am now attempting to drag the desired widgets into the layout.

Unfortunately, the new Horizontal Layout widget is infinitely thin:

Infinitely Thin Layout

... and I cannot drag my "Import Progress" label widget or my progress bar widget into the new horizontal layout widget.

Note that when I attempt to drag the desired widgets over the new horizontal layout widget, Qt Designer does not do anything useful for me in terms of expanding the drop region to make the horizontal widget available as a drop target. So I'm stuck.

How do I add widgets to an infinitely-thin layout widget in Qt Designer?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181

3 Answers3

72

Select the layout, and then drop the widget onto the corresponding selected item in the Object Inspector pane. If you find it tricky to select the layout on the actual form, you can also select it via the Object Inspector pane.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • 27
    Thanks, its really strange that dragging from inside the object inspector is not possible but dropping to is... – fivef Jan 26 '15 at 12:58
  • 3
    That's ridiculous. It took me a day of trying to cut&paste items in the Object Inspector to the correct places, since dragging doesn't work, and getting "Cannot paste widget" errors, finally editing the XML manually... and now I find by chance that this works after all... in the most brainded way possible. Better late than never, I guess. _Thanks_. – nyov Feb 26 '19 at 22:44
  • 2
    I had the same problem. It is bizarre that this is not an easy thing to do. – Gavin Smith Apr 07 '19 at 13:47
  • Thanks for this tip that has made QtDesigner finally usable to me! I'd file an issue but that has been going on for so long that they probably don't consider fixing it... – YvesQuemener Nov 11 '20 at 10:27
  • This doesnt seem to work in a horizontal layout. The first widget fills the entire layout, dropping another onto the same layout adds it to that layout's parent instead. puzzling application. – oarfish Oct 12 '22 at 16:23
  • Actually it seems the red stop sign is an indicator that it doesnt work … if you add layouts everywhere to make that go away, you can then drop widgets. – oarfish Oct 12 '22 at 16:39
8

One way (that I usually do as a workaround for not having to show the structure panel) is to select the layout, setting the top or bottom margins to any value (10, whatever) and then dragging the component into the layout. Yeah, that is just for the pure pleasure of dropping the component in the layout, i know, but is a way.

Lucas Franceschi
  • 398
  • 6
  • 12
5

My small trick:

  • Select layout
  • Change temporary "layoutTopMargin"
  • Drop into layout required widgets
  • Restore layoutTopMargin to default 0
Dmitry Ivanov
  • 508
  • 7
  • 9