0

Enabling a ticks for QSlider seems to mess up the sizeHint of the slider itself.

Consider this simple code:

#include <QApplication>

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   QSlider ds{Qt::Horizontal};

   ds.setRange(0, 100);
   ds.setTickPosition(QSlider::TicksAbove);
   ds.setTickInterval(20);
   ds.show();

   return a.exec();
}

and this is how is rendered:

enter image description here

notice how the slider is cropped below.

this behaviour is the same in a complex widget too of course:

enter image description here

Resizing the window of the first slider tick position does not follow the slider itself.

enter image description here

So the question is how have a QSlider rendered properly with ticks enabled?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Moia
  • 2,216
  • 1
  • 12
  • 34

2 Answers2

1

I would recommend to add VerticalSpacers at the top and bottom, which are set to "expanding" So that the slider is sandwiched. So when you resize the whole widget, for vertical changes th slider stays minimumHeight, but for horizontal changes it expands (at least this is what I expect what you want to achieve).

Marcel Petrick
  • 454
  • 3
  • 15
0

The practical way I found to solve this is to set the minimum size manually to the bare minumum to avoid the incorrect render:

ds.setMinimumHeight(30);
Moia
  • 2,216
  • 1
  • 12
  • 34