Search code examples
c++qtparent-childqwidgetqtstylesheets

How to exclude a specific widget ( QToolTip ) from the stylesheet applied on the parent


I have a widget class derived from QWidget. Earlier, there was a stylesheet applied on it, to set the font size of all the string in the widget

setStyleSheet( QString( "font-size: %1px;" ).arg( fontSize ) );

This was resulting in all the strings in the widget to have a specific font size. But I would like to have the tooltips in the widget to have the default font style.

Is there a way to achieve this?

I found a similar question in Qt Centre: Setting stylesheet for "almost" all widgets.


Solution

  • You can set the first font size to all widgets with the * selector, and then the second font size to QToolTip objects with type selector:

    setStyleSheet("*{font-size: 20px;} QToolTip{ font-size: 8pt; }");