Inter-changeable style sheets, are they possible?



  • I can see that the style sheet code I have put into gui via Qt Designer is put into the project.ui xml document and is not actually its own file as per CSS.

    What if I want more than one look and feel for a project? Is there any way to have multiple 'style sheets' like I would do with CSS so styles can be interchanged?


  • Moderators

    Yes. You can have many style sheets stored in files on your disk, and then just load them using QWidget::setStyleStheet().



  • Doh! How did I miss that?? Thanks :-)


  • Moderators

    No problem, mate :)

    Just be careful, styles follow parent-child hierarchy, which can lead to some headaches at times ;)



  • Derailed now back onto this.

    Got any example files? I took the css code from QtCreator (which was working fine), created a new css file in VS 2010 project, loaded it in the app (setStyleString gets a valid string of css). No styles applied and I cannot seem to find an actual example file just snippets of css (qss to be picky!!)
    @
    body
    {
    /labels/
    QLabel
    {
    color: rgb(255, 255, 0);
    font: 24px;
    background-color:transparent;
    }
    /list views/
    QListView
    {
    background-color:transparent;
    font:24px;
    }
    QListView::item
    {
    color: rgb(255, 255, 0);
    font: 24px;
    border-width:5px;
    border-style: inset;
    padding: 5px;
    margin:5px;
    }
    QListView::item:selected
    {
    border: 10px solid #990066;
    }
    QListView::item:selected:!active
    {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #ABAFE5, stop: 1 #8588B2);
    }

     QListView::item:selected:active 
    {
      background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6a6ea9, stop: 1 #888dd9);
    }
    
    QListView::item:hover 
    {
      background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #FAFBFE, stop: 1 #DCDEF1);
    }
    /*Buttons*/
    QPushButton
    {
      color:white;
      font:20px;
      border-width: 1px;
      border-color: #339;
      border-style: solid;
    }
    QPushButton:pressed
    {
       border-style: inset;
    }
    

    }
    @

    [Edit: Added @-tags -- mlong]


  • Moderators

    Doh, I have one, but it's proprietary, I cannot distribute it, at least not without going through some bureaucratic arrangements with people above ;)

    I'm not too familiar with QSS, I have used it only occasionally myself. The part "body" seems out of place. What is it for? Try running the code without it. And make sure that the application actually sees the file and reads it properly (you know, somtimes the build automatically places the binary in another folder, and if your paths are relative, it might not find the file).



  • I originally just placed the code from the creator into the file and that did not work (by debugging I can see the content of the file is being read) so I used Qt tools to create a file and it put that body tag in so I tried that.

    Thanks any way.



  • Hey, now I am a badger!



  • File encoding was wrong....... phew!


  • Moderators

    hah :) It's usually some small detail like this. So you are good now?



  • I'm always a good girl ;-)


Log in to reply
 

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