Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using a stylesheet to customize a QSlider
Forum Updated to NodeBB v4.3 + New Features

Using a stylesheet to customize a QSlider

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 10.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    Consider the following code snippet that creates a single QSlider:
    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {
    resize(700, 800);
    setStyleSheet("QSlider { width: 40px }"
    "QSlider::groove:horizontal {"
    "border: 1px solid #999999;"
    "background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);"
    "height: 50px;"
    "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: 50px;"
    "margin: -5px 0 -5px 0;"
    "border-radius: 3px;}");

    QSlider *slider;
    // Here are two ways of creating a qslider
    
    // the following line of code makes a slider of about 120 pixels in width
    // changing the first width & height in the stylesheet have no effect
    // but changing the last width (handle width) does work
    

    // slider = new QSlider(Qt::Horizontal, this);

    // the following two lines of code make a slider that's much wider (around 650 pixels)
    // changing the first width in the stylesheet has no effect
    // but changing the groove height and handle width do take effect
    

    // slider = new QSlider(Qt::Horizontal);
    // slider->setParent(this);

    slider->move(25, 100);
    

    @
    Ultimately, I'd like to make this QSlider vertical, but for right now, I'm wondering why the two ways of instantiating the slider behave so differently. I looked around for a good explanation of what's going on but couldn't find any.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved