-1

I'm not an expert of pyqt and Qt Designer. I have a trivial problem that I cannot solve.

Very simple, within a QScrollBar I have some labels and some checkboxes. In Qt Designer all is going right:

enter image description here

In the code I have to interactively change the label text when some parameters are choose, and it works. But when I set the new text for the label (longer than the default one) then the label text is not shown completely:

enter image description here

If I try to add a minimum width this is the result:

enter image description here

In the code I tried also some methods of the label, without any result:

h = self.x_label.sizeHint()
print(h)
self.x_label.setMinimumSize(h)

In Designer I also tried all the possible combination of the Horizontal Policy of both the labels and the comoboxes.

does somebody know some method (code or directly in designer) that will expand the x_label?

matteo
  • 4,683
  • 9
  • 41
  • 77

1 Answers1

0

It looks like you are adding the controls directly onto the form. That's normally OK, but can be a problem in certain circumstances as you've experienced.

The best way to manage your issue is layouts. If you look the Widget Box pane on the left of the Designer, you will see at the top four Layout controls: Vertical Layout, Horizontal Layout, Grid Layout and Form Layout.

Why do you want a Layout? The Layout will handle the relationship between the controls for you. If you resize one control - for example by changing the text on the label - the other controls will resize to fit.

You probably want the Form Layout - it's a shortcut to having a column of controls with labels on the left and the combobox on the right.

Alan
  • 2,914
  • 2
  • 14
  • 26
  • sorry for the delay.. actually I'm using layout (grid layout). If I change the layout from grid to form, when the code changes the label, the label itself disappear... – matteo Mar 22 '17 at 18:46
  • You'll need to post the designer file and the code you are using. – Alan Mar 22 '17 at 20:18