PDA

View Full Version : How to rotate a QSlider?



Gokulnathvc
2nd January 2018, 11:41
How to rotate a QSlider which is placed on a Qlabel?

d_stranz
2nd January 2018, 18:45
One would think that QAbstractSlider::setOrientation() would do it. One also wonders why you would want to put a slider into a label in the first place and not just make a composite widget that contains a layout with the slider and label placed separately in it. QLabel isn't really designed to hold child widgets, despite being derived from QFrame.

Gokulnathvc
3rd January 2018, 04:47
I have already placed Horizontal slider holding Custom groove and handle , but I want to rotate the QSlider in a slanting position say about 15 to 20 degrees..

Gokulnathvc
3rd January 2018, 06:56
Here is the code what I have tried.:

QGraphicsScene *scene = new QGraphicsScene(this);
ui->horizontalSlider->setParent(ui->graphicsView);
QGraphicsProxyWidget *w = scene->addWidget(ui->horizontalSlider);
w->setPos(0,45);
w->setRotation(12);
ui->graphicsView->setScene(scene);
ui->graphicsView->show();
ui->graphicsView->rotate(12);

ChrisW67
3rd January 2018, 08:30
So, you want to arbitrarily rotate a QGraphicsProxyWidget, containing a QSlider, in a QGraphicsScene. This has nothing to do with a QLabel. I hope you can see that your original question was never going to get you a useful answer.

This works as advertised:


#include <QtWidgets>

int main(int argc, char **argv) {
QApplication app(argc, argv);

QSlider *slider = new QSlider();

QGraphicsScene scene;

QGraphicsProxyWidget *p = scene.addWidget(slider);
p->setRotation(20);

QGraphicsView view(&scene);
view.show();

return app.exec();
}

d_stranz
4th January 2018, 00:22
Not only that, but it looks like for some reason the OP was using Qt Designer to create a QSlider as part of another widget's UI, and then stealing it to put into the graphics proxy. Clearly is unaware of the concept of creating widgets on the fly in code.