Results 1 to 2 of 2

Thread: Promlems with setStyleSheet

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Promlems with setStyleSheet

    Hi to all,
    I'm doing some test with the style sheet. I'm trying to customize a QSlider.
    I create a class inherited from QFrame containing just a QSlider so:
    Qt Code:
    1. #ifndef __VOLWIDGET_H__
    2. #define __VOLWIDGET_H__
    3.  
    4. #include <QFrame>
    5. #include <QSlider>
    6.  
    7. class VolWidget : public QFrame
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. VolWidget( QWidget* parent );
    13. virtual ~VolWidget();
    14.  
    15. signals:
    16. void sig_volChanged(int);
    17.  
    18. protected:
    19.  
    20. private:
    21. QSlider* m_volSlider;
    22. };
    23. #endif // __VOLWIDGET_H__
    To copy to clipboard, switch view to plain text mode 
    After creating the QSlider in the ctor I would apply to it a style using the setStyleSheet routine.

    Qt Code:
    1. VolWidget::VolWidget( QWidget* parent )
    2. : QFrame(parent)
    3. {
    4. setFrameStyle( QFrame::Panel | QFrame::Raised );
    5.  
    6. setStyleSheet(" QSlider::groove:vertical { \
    7. background: red; \
    8. position: absolute; \
    9. left: 4px; \
    10. right: 4px; }\
    11. QSlider::handle:vertical { \
    12. height: 10px; \
    13. background: green; \
    14. margin: 0 -4px; /* expand outside the groove */ } \
    15. QSlider::add-page:vertical { \
    16. background: white; } \
    17. QSlider::sub-page:vertical { \
    18. background: pink; }");
    19.  
    20. m_volSlider = new QSlider(Qt::Horizontal);
    21. m_volSlider->setMinimum( 0 );
    22. m_volSlider->setMaximum( 100 );
    23. m_volSlider->setValue( 100 );
    24.  
    25. QVBoxLayout *vLayout = new QVBoxLayout();
    26. vLayout->setContentsMargins(0, 0, 0, 0);
    27. vLayout->addWidget(m_volSlider);
    28.  
    29. setLayout(vLayout);
    30.  
    31. connect(m_volSlider, SIGNAL( valueChanged(int) ), this, SIGNAL( sig_volChanged(int) ) );
    32. }
    To copy to clipboard, switch view to plain text mode 

    In my case the code has no effect. No style sheet is applied to the QSlider.
    Where I'm wrong?
    Regards
    Franco Amato

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Promlems with setStyleSheet

    Your code is correct, the reason you not able to see the style sheet applied is...

    You are setting style for QSlider::groove:vertical, QSlider::handle:vertical, QSlider::add-page:vertical and QSlider::sub-page:vertical, all these are vertical components; and you are adding a new QSlider(Qt::Horizontal), which uses horizontal components

    so either change you style to horizontal, or change QSlider to vertical

Similar Threads

  1. QMenu and setStyleSheet
    By BobTheProg in forum Qt Programming
    Replies: 5
    Last Post: 9th July 2010, 13:28
  2. QTableWidget and setStyleSheet()
    By kazek3018 in forum Newbie
    Replies: 3
    Last Post: 30th December 2008, 08:52
  3. Problem to setstylesheet
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2008, 06:57
  4. using setStyleSheet
    By Weilor in forum Qt Programming
    Replies: 11
    Last Post: 18th January 2008, 13:41
  5. QApplication::setStyleSheet()
    By Ryhel in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2007, 13:09

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.