Qt 4.8 QSlider handle size
-
Hi I googled that Gentoo release and it seems that there's no online installation of Qt 4.8.4 available for it, so I think your version of Qt 4.8.4 is custom built, i.e. built by downloading the source for Qt 4.8.4 and compiling. And in that process some features might have been dropped, for example z-order for widgets.
So I simplified my example to not to rely on a working z-order, please try this version:#include <QApplication> #include <qslider.h> class Window : public QWidget { Q_OBJECT // setup 2 real sliders and 2 "followers" that are stacked under the real ones QSlider* pSlider1; QSlider* pSlider1Follower; QSlider* pSlider2; QSlider* pSlider2Follower; public: Window() { setGeometry(130,130,860,660); pSlider1Follower = new QSlider(Qt::Horizontal,this); pSlider1Follower->setTickPosition(QSlider::TicksBothSides); pSlider1Follower->setTickInterval(2); pSlider2Follower = new QSlider(Qt::Vertical,this); pSlider2Follower->setTickPosition(QSlider::TicksBothSides); pSlider2Follower->setTickInterval(2); pSlider1 = new QSlider(Qt::Horizontal,this); pSlider2 = new QSlider(Qt::Vertical,this); connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int))); connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int))); // do an initial update/refresh valueChanged1(0); valueChanged2(0); } public slots: void valueChanged1(int value) { pSlider1Follower->setValue(value); pSlider2->setStyleSheet(QString("QSlider::groove { background: transparent; width: %1px; } " "QSlider::handle { background: #eeeeee; border:1px solid grey; height: %2px;}").arg(value + 30).arg(value * 2 + 10)); pSlider2->setGeometry(660,30,2 * value + 30,600); pSlider2Follower->setGeometry(660,30,2 * value + 30,600); } void valueChanged2(int value) { pSlider2Follower->setValue(value); pSlider1->setStyleSheet(QString("QSlider::groove { background: transparent; height: %1px; } " "QSlider::handle { background: #eeeeee; border:1px solid grey; width: %2px;}").arg(value + 30).arg(value * 2 + 10)); pSlider1->setGeometry(30,300,600,2 * value + 30); pSlider1Follower->setGeometry(30,300,600,2 * value + 30); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); Window window; window.show(); return app.exec(); } #include "main.moc"
If it bulds ok, lets' debug:
- How many sliders do you see?
- If you move one of them, does it cause any other slider to move as well?
- If you move one of them, does it cause any other slider to change in size?
-
- 2 Sliders, 1 horizontal and 1 vertical, with two handles on each, the horizontal slider handles do not look correct.
2 . Moving the vertical slider causes both vertical handles to move together, the coloured square handle is correct orientation, this also increases height of horizontal slider.
Moving the horizontal slider increases the width of the vertical slider, but the handles are not together, one is the correct orientation but centered.
- Vertical handles are in sync. Horizontal are not.
-
Hi, as you say, the vertical slider looks ok but not the horizontal one. Sure you copied my program ok? If you check with wc it should say:
70 166 2117 main.cpp
and the md5 sum:
md5sum main.cpp 1eaf936e1072bf34bbb817a942295ada main.cpp
could you take a photo of the code after public slots: it should look like this:
Sorry to bother but over the years, many times I've been struck by that "not copied verbatim" bug...
-
@hskoglund, I've been through the source again an yes there was an error in the CSS, which having corrected this what I'm seeing is still four handles, where the underlying handles are orientated incorrectly, the handles on-top of these are orientated as I would expected.
Moving the vertical slider increases the width of the horizontal slider.
Moving the horizontal slider increases the height of the vertical slider. -
Aha nice! So if they move together (both horizontally and vertically) that means your screen now looks similar to my screenshot 5 days ago?
Which means you can use this as a solution for displaying classical grooves and simultaneously having resizable QSlider handles on your Qt 4.8.4... -
@hskoglund , I know this is quite an old post now, I've been working on other stuff and now revisiting this, here are a few observations:
- With QSlider style set as follows:
QSlider::groove:vertical { background: transparent; } QSlider::handle:vertical { background: #eeeeee; border: 1px solid grey; width: 80px; height: 10px; } QSlider::groove:horizontal { background: transparent; } QSlider::handle:horizontal { background: #eeeeee; border: 1px solid grey; width: 10px; height: 80px; }
With the above both handles appear the correct size and orientation. No groove is obviously visible.
If I remove the content of the groove style just leaving:
QSlider::groove:vertical { } QSlider::handle:vertical { background: #eeeeee; border: 1px solid grey; width: 80px; height: 10px; } QSlider::groove:horizontal { } QSlider::handle:horizontal { background: #eeeeee; border: 1px solid grey; width: 10px; height: 80px; }
Whilst the groove and ticks are now visible the handle is the wrong way in both orientations.