January 9, 2011

ivan.todorovich ivan.todorov..
Lab Rat
96 posts

QSS Styling a QToolBox’s Page.

 

Hi,

I found out that targeting the page widgets can be a little tricky.
One would simply think that it would be easy as

but no. The solution is this:

QToolBox creates a QScrollArea for every page as a container, and QScrollArea has a viewport where it puts its widget. So your page isn’t a direct children neither from QToolBox nor QScrollArea.

I hope this helps some of you..
Cya!

 Signature 

o_o Sorry for my rusted english.

10 replies

January 9, 2011

Volker Volker
Robot Herder
5428 posts

Good point. Would you mind creating a wiki page for it (in the How To [developer.qt.nokia.com] section)

January 9, 2011

ivan.todorovich ivan.todorov..
Lab Rat
96 posts

Ok.. i’ve created the wiki page. http://developer.qt.nokia.com/wiki/Style_a_QToolBoxs_Page_with_QSS

 Signature 

o_o Sorry for my rusted english.

January 9, 2011

peppe peppe
Ant Farmer
1026 posts

Why are you using the child selector and not the descendant selector + an id/property selector (to avoid blindly matching every QToolBox subwidget)?

I.e.

  1. QToolBox QWidget#myId { ... }

or

  1. QToolBox QWidget[myProperty="true"] {...}

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

January 9, 2011

ivan.todorovich ivan.todorov..
Lab Rat
96 posts

i am not matching every QToolBox subwidget, just the page widgets..
because i may not necessary know the ids or the widgets nor want to select by a specific property.


is very different to

That last one would match every QToolBox sub-widget.

I think you are mistaken—

 Signature 

o_o Sorry for my rusted english.

January 9, 2011

peppe peppe
Ant Farmer
1026 posts

That’s why I said


an id/property selector (to avoid blindly matching every QToolBox subwidget)?

I.e.

  1. QWidget *w = new QWidget;
  2. w->setObjectName("MyWidget");
  3. toolbox->addItem(w, "foo");

styled with

  1. QToolBox QWidget#MyWidget { ... }

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

January 9, 2011

ivan.todorovich ivan.todorov..
Lab Rat
96 posts

What if you created the pages with QtDesigner?
And you want to target every QToolBox page. IE: Give they a white background-color.

 Signature 

o_o Sorry for my rusted english.

January 9, 2011

peppe peppe
Ant Farmer
1026 posts
What if you created the pages with QtDesigner? And you want to target every QToolBox page. IE: Give they a white background-color.

You simply change each page’s object name, or set a dynamic property on them with a value of yours. What I am pointing out is NOT that your solution doesn’t work, but that requires how QToolBox is internally implemented. My solution instead “just works”.

Check it out: http://qt.pastebin.com/4X2ZfHWz

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

August 18, 2011

Tedisito Tedisito
Lab Rat
5 posts

Hey,
I tried the solution of peppe, it works but only in the Qt designer, then when you run the application the background color of the Qtoolbox page does not appear like in Qt Designer but with the grey color.
While in contrast, the solution of ivan works in both cases.

I am trying to make the page transparent but it seems that it does not work. Do you know why? And how to make the QToolBox page transparent?

Thank you

August 18, 2011

peppe peppe
Ant Farmer
1026 posts

  1. #include <QtGui>
  2.  
  3. int main(int argc, char **argv)
  4. {
  5.     QApplication app(argc, argv);
  6.  
  7.     QToolBox toolBox;
  8.  
  9.     for (int i = 0; i < 5; ++i) {
  10.         toolBox.addItem(new QWidget, QString("Tab #%1").arg(i));
  11.     }
  12.    
  13.     toolBox.widget(0)->setProperty("myProperty", true);
  14.     toolBox.widget(1)->setProperty("myProperty", true);
  15.    
  16.     toolBox.show();
  17.  
  18.     app.setStyleSheet("QToolBox QWidget[myProperty=\"true\"] { background-color: white; }");
  19.  
  20.     return app.exec();
  21. }

This is still working for me (notice that object names / dynamic properties must be set before the stylesheet, due to how Qt style sheets work). What do you mean with “make the page transparent”? Like, a “hole” inside the QToolBox?

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

August 18, 2011

Tedisito Tedisito
Lab Rat
5 posts

Thanks for the notice, that was why it didn’t work.
By make the page transparent, I mean have a hole inside the QToolBox. And actually not a “hole” like 100% transparent but I would to set the transparency.

For example, if you set the stylesheet with:

  1. QToolBox QWidget[myProperty=\"true\"] { background-color: rgba(0, 255, 0,20); }

You’ll see some green and the transparency are here too BUT still with the gray in background. Like if there is another widget to set!

 
  ‹‹ QThread with signals and slots      Qt for hardware acceleration ››

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