-1

how to make number follow the bar size?

in this qt designer, i create frame which contain bar, and qlabel =500\n\n250\n\n0\n\n-250\n\n-500

Is there a way to create legend in this bar?

or can we make qlabel follow the size of bar?'

Progressbar in normal size

Progressbar that get extended

M.F.J
  • 9
  • Use [layout managers](//doc.qt.io/qt-5/layout.html). For instance, a horizontal layout with the progress bar on the left, and a vertical layout on the right, then add the labels to that vertical layout. – musicamante Sep 08 '22 at 16:16
  • @musicamante already try it, but it doesnt work, in my code i just use \n to give space for every number in the qlabel. so when i expand it, its not in the right position of the bar. or what you mean is i put many label in one vertical layout? not in one qlabel? – M.F.J Sep 08 '22 at 16:38
  • Exactly, use more labels, one for each value. – musicamante Sep 08 '22 at 17:28

1 Answers1

0

If I wasn't interested in having accuracy, I would create a structure with layouts like this

QHorizontalLayout
-> QProgressBar
-> QVerticalLayout
   -> QLabel (500)
   -> QLabel (250)
   -> QLabel (0)
   -> QLabel (-250)
   -> QLabel (-500)

But If accuracy is your priority you should start thinking of making your own custom widget.

p.s. the above is not code, but rather a representation of the widget hierarchy that I suggest. I have just formatted it as a code snippet, just to show the hierarchy :)

willy
  • 487
  • 5
  • 21