Custom widget stylesheet



  • I have my own QWidget based class

    class LFVResizeBar : public QWidget
    {
        Q_OBJECT
    
    public:
        LFVResizeBar(QWidget *parent = 0);
        ~LFVResizeBar();
    
    protected:
    
      void resizeEvent(QResizeEvent *event);
      void paintEvent(QPaintEvent *event);
    
    private:
        Ui::LFVResizeBar ui;
    };
    
    

    and in constructor I'm setting

    setStyleSheet("QWidget#LFWindowTitlteBar{background: black;}"); // object name is LFWindowTitlteBar
    

    but without effect :( what's the problem?



  • Hi! Are you sure you set the object name? What does qDebug() << objectName(); print when called from LFWindowTitlteBar? Where is the setObjectName("LFWindowTitlteBar"); call?



  • @Alatriste said:

    // object name is
    I told you in my code..

    object name is LFWindowTitlteBar

    setStyleSheet("QWidget#LFWindowTitlteBar{background: black;}"); // object name is LFWindowTitlteBar
    

  • Qt Champions 2016

    @Alatriste
    Hello,
    But where do you set the object name? Could you provide the class' constructor and this implementation LFVResizeBar::paintEvent(QPaintEvent *event) as well?

    Kind regards.



  • If LFVResizeBar is the widget class you want to target, I would suggest changing your CSS to QWidget#LFVResizeBar, and in the constructor of the LFVResizeBar or somewhere you need to set the name of the object to "LFVResizeBar" so the CSS will match it as Wieland indicated.

    It may work if the name doesn't match the class, but just for consistency and maintainability sake I would have them be the same.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.