Qt ticker slider widget with tick text labels

I am looking for a Qt widget such as QSlider, but with support for text labels, for example: example widget

I will use this widget as a mode switch. Have you met something like this?

+7
source share
2 answers

I would use QSlider with QLabel (s) as shown below. My usual caveat is that you may need some fine tuning and tuning yourself.

main.cpp

 #include <QMainWindow> #include <QApplication> #include <QGridLayout> #include <QSlider> #include <QLabel> class MainWindow Q_DECL_FINAL : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = Q_NULLPTR) : QMainWindow(parent) { QSlider *slider = new QSlider(Qt::Horizontal, this); slider->setRange(1, 4); slider->setSingleStep(1); QLabel *label1 = new QLabel("Novice", this); QLabel *label2 = new QLabel("Intermediate", this); QLabel *label3 = new QLabel("Advanced", this); QLabel *label4 = new QLabel("Expert", this); QGridLayout *layout = new QGridLayout; layout->addWidget(slider, 0, 0, 1, 4); layout->addWidget(label1, 1, 0, 1, 1); layout->addWidget(label2, 1, 1, 1, 1); layout->addWidget(label3, 1, 2, 1, 1); layout->addWidget(label4, 1, 3, 1, 1); setLayout(layout); } }; #include "main.moc" int main(int argc, char **argv) { QApplication application(argc, argv); MainWindow mainWindow; mainWindow.show(); return application.exec(); } 

main.pro

 TEMPLATE = app TARGET = main QT += widgets SOURCES += main.cpp 

Assembly and launch

 qmake && make && ./main 
+14
source

You can use my extended QSlider class in git .

+2
source

Source: https://habr.com/ru/post/1209939/


All Articles