Results 1 to 4 of 4

Thread: QSlider: changing the groove without changing the handle

  1. #1
    Join Date
    Sep 2009
    Posts
    19
    Qt products
    Platforms
    Unix/X11

    Default QSlider: changing the groove without changing the handle

    Hi!

    I wanted to modify the groove of a slider while keeping the original handler but it didn't seem to work...

    If I just define the groove in the stylesheet, the groove looks as expected but the handle disappears...

    Any hint?

  2. #2
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QSlider: changing the groove without changing the handle

    Hi,
    It would be easier seeing a picture of what you are trying to do. I don't know if this helps or not but here is a stylesheet I used for my sliders ( I am using images for the groove and handle). Maybe it will give you some hints.
    Qt Code:
    1. QSlider::groove:horizontal {border-image: url(icons:guage_cursor_bg1.png);
    2. border-width: 1px; height: 31px;}
    3. QSlider::handle:horizontal {margin-top:0px; margin-bottom:-1px;
    4. image: url(icons:guage_cusor_n.png);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2009
    Posts
    19
    Qt products
    Platforms
    Unix/X11

    Default Re: QSlider: changing the groove without changing the handle

    Well... Here is my code:
    Qt Code:
    1. #!/usr/bin/env python
    2. # coding: utf-8
    3. from PyQt4.QtCore import *
    4. from PyQt4.QtGui import *
    5. import sys
    6.  
    7. app = QApplication(sys.argv)
    8.  
    9. style = """QSlider::groove:horizontal {
    10. border: 1px solid #999999;
    11. height: 8px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
    12. background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);
    13. }
    14. """
    15.  
    16. slider = QSlider()
    17. slider.setOrientation(Qt.Horizontal)
    18. slider.setStyleSheet(style)
    19.  
    20. layout = QVBoxLayout()
    21. layout.addWidget(slider)
    22.  
    23. widget = QWidget()
    24. widget.setLayout(layout)
    25. widget.show()
    26.  
    27. app.exec_()
    To copy to clipboard, switch view to plain text mode 
    and here is the result
    QSlider.png

  4. #4
    Join Date
    Apr 2013
    Posts
    1
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11

    Default Re: QSlider: changing the groove without changing the handle

    For most widgets, when you set stylesheet for one component, you may have to define stylesheets for other components too.

    Like the QSlider, QScrollBar etc.

    Here, defining both the groove and the handle in the stylesheet caused it to work.

Similar Threads

  1. QSlider: Increase handle size -> How ?
    By ArneBurghardt in forum Qt Programming
    Replies: 6
    Last Post: 11th August 2016, 20:58
  2. Hide QSlider groove
    By kwikness in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2010, 07:21
  3. customize the groove of qslider
    By oscar_chen in forum Qt Programming
    Replies: 0
    Last Post: 13th May 2010, 08:26
  4. Replies: 2
    Last Post: 10th August 2009, 09:45
  5. QSlider custom handle image not displayed
    By planglois in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2008, 13:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.