Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:Customizing QSlider

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.

This article shows how to create custom slider based on QWidget.

Article Metadata
Tested with
Devices(s): Nokia N97
Platform(s): S60 5th Edition
Keywords: QSlider
Created: divanov (20 May 2010)
Last edited: hamishwillee (11 Oct 2012)

Source Code

#include <QtGui>
int main (int argc, char **argv)
QApplication app(argc, argv);
app.setStyleSheet("QSlider { height: 30px}"
"QSlider::groove:horizontal {"
"border: 1px solid #999999;"
"background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);"
"height: 26px;"
"margin: 0 0 0 0;}"
"QSlider::handle:horizontal {"
"background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);"
"border: 1px solid #5c5c5c;"
"width: 30px;"
"margin: -2px 0 -2px 0;"
"border-radius: 3px;}");
QWidget widget;
QVBoxLayout *layout = new QVBoxLayout;
QSlider *slider;
slider = new QSlider(Qt::Horizontal);
layout->addWidget(slider, 0, Qt::AlignBottom);
slider = new QSlider(Qt::Horizontal);
layout->addWidget(slider, 0, Qt::AlignTop);
return app.exec();

setStyleSheet() holds the application style sheet. QSlider is used to create the slider, and QVBoxLayout to create the layout. First we add the slider to the layout and then call setLayout() to set the layout to the widget. We make spacing between the sliders with setSpacing(). Finally show() is called to display the widget.


This page was last modified on 11 October 2012, at 01:14.
101 page views in the last 30 days.