May 24, 2012

Dolphin Dolphin
Ant Farmer
123 posts

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?

10 replies

May 24, 2012

sierdzio sierdzio
Area 51 Engineer
2536 posts

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

 Signature 

(Z(:^

May 24, 2012

Dolphin Dolphin
Ant Farmer
123 posts

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

May 24, 2012

sierdzio sierdzio
Area 51 Engineer
2536 posts

No problem, mate :)

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

 Signature 

(Z(:^

June 15, 2012

Dolphin Dolphin
Ant Farmer
123 posts

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!!)

  1. body
  2. {
  3.     /*labels*/
  4.     QLabel
  5.     {
  6.      color: rgb(255, 255, 0);
  7.      font: 24px;
  8.       background-color:transparent;
  9.     }
  10.     /*list views*/
  11.     QListView
  12.     {
  13.      background-color:transparent;
  14.      font:24px;
  15.     }
  16.     QListView::item
  17.     {
  18.      color: rgb(255, 255, 0);
  19.      font: 24px;
  20.      border-width:5px;
  21.      border-style: inset;
  22.      padding: 5px;
  23.       margin:5px;
  24.     }
  25.     QListView::item:selected
  26.     {
  27.          border: 10px solid #990066;
  28.     }
  29.     QListView::item:selected:!active
  30.     {
  31.          background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #ABAFE5, stop: 1 #8588B2);
  32.     }
  33.  
  34.      QListView::item:selected:active
  35.     {
  36.       background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6a6ea9, stop: 1 #888dd9);
  37.     }
  38.  
  39.     QListView::item:hover
  40.     {
  41.       background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #FAFBFE, stop: 1 #DCDEF1);
  42.     }
  43.     /*Buttons*/
  44.     {
  45.       color:white;
  46.       font:20px;
  47.       border-width: 1px;
  48.       border-color: #339;
  49.       border-style: solid;
  50.     }
  51.     QPushButton:pressed
  52.     {
  53.        border-style: inset;
  54.     }
  55. }

[Edit: Added @-tags — mlong]

June 15, 2012

sierdzio sierdzio
Area 51 Engineer
2536 posts

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).

 Signature 

(Z(:^

June 18, 2012

Dolphin Dolphin
Ant Farmer
123 posts

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.

June 18, 2012

Dolphin Dolphin
Ant Farmer
123 posts

Hey, now I am a badger!

June 19, 2012

Dolphin Dolphin
Ant Farmer
123 posts

File encoding was wrong……. phew!

June 19, 2012

sierdzio sierdzio
Area 51 Engineer
2536 posts

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

 Signature 

(Z(:^

June 19, 2012

Dolphin Dolphin
Ant Farmer
123 posts

I’m always a good girl ;-)

 
  ‹‹ Mixing C and C++/Qt code      How to deal with foreign key in Qt? ››

You must log in to post a reply. Not a member yet? Register here!