1

I have a Widgets with LineEdit 's to set some int values. To make that easier, I have an additional QToolButton which shall show a QSlider to modifiy that value.

IMPORTANT: The Slider is intially hidden! It shall only appear if the Button was pressed. When I have 20 slidersWidgets in a row, I would waste the space for each of them, if put in a predefined layout. If the space is not required until popup, window adjustments would be required then.

The screenshot represents on ValueSelectorWidget. I have multiple of them listed.

In the ValueSelectorWidget class I have:

valveSlider = new QSlider(Qt::Horizontal, this);

As you can see on the screen shot, when I click on the left ToolButton, a QSlider appears. Screenshot

On the top left side of the ValueSelectorWidget because of the this in the QSlider object cration above.

How can I place that slider arround of the left ToolButton (sliderButton) ?

  QPoint sliderButtonPos = sliderButton->pos();
  sliderButtonPos.rx() + 50 ;
  sliderButtonPos.ry() + 50;

  valveSlider->setGeometry(sliderButtonPos.x(), sliderButtonPos.y(), 120, 20);

As in the following : screenshot When I press the red dot button, the Slider shall appear next to it or next to the current mouse position.

But that did not work either. Any suggestions? Thanx in advance.

Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

2 Answers2

0

You can add this slider in the designer to the layout together with the other widgets. Then just call smth like widget.slider1->setVisible(false); for the slider in the constructor to hide it at the begining. And in the button click slot make smth like widget.slider1->setVisible(true);. You need to check how layouts work for clear understanding of widgwets positions.

johngull
  • 819
  • 6
  • 22
  • Imagine I have 20 ValueSelectorWidget in a VerticalLayout. When I put all those invisible sliders into a layout, I would have wasted 20 spaces for sliders, especially if not used. When the space is not required until show() I would have alignment adjustments then. Both inadequate. I would like an independant popup near to a QButton. – Ralf Wickum Oct 16 '15 at 15:07
  • The layout adapts sizes on showed widget, so there won't be "wasted spaces" here. If you hide the slider, the other widget will take the freed place to expand themselves – Benjamin Debotté Oct 16 '15 at 20:09
0

You shouldn't design your GUI by using coordinates. Instead use the different layouts given by Qt : http://doc.qt.io/qt-5/qlayout.html#details could be a great start !

Now that your widgets are perfectly aligned, consider @johngull answer to hide/display your slider. For instance, you can connect your button onClick signal to toggle the displaying of your slider