Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to apply QStyleSheet Formatting on WhatsThis text

How to apply QStyleSheet Formatting on WhatsThis text

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 2 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? A Former User

    I'm using 5.6 here and I just checked the .cpp file. You're right, it inherits QWidget. Which makes it even less understandable why a simple stylesheet like this wouldn't work:

    QWhatsThis
    {
      background: rgb(255,255,127);
      color(67, 67, 67);
      ...
    }
    

    I am using the public static method enterWhatsThisMode() to put my QDialog into WhatsThis mode and show the respective help texts for each widget in the dialog.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #6

    @tobiSF
    do you apply the stylesheet to Application ?

    I wonder what QWhatsX is a child of. (runtime).

    Also my class is called/ends with That
    Yours are really called QWhatsThis ?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #7

      @mrjj,
      yes, I have a static method ApplicationStyleManager::loadDefaultStyle() that loads and sets the stylesheet:

      void ApplicationStyleManager::loadDefaultStyle()
      {
      	QSettings settings;
      	QString path = settings.value("style/default.qss").toString();
      
      	if(!path.isEmpty())
      	{
      		QFile file(path);
      		if (file.open(QFile::ReadOnly))
      		{
      			QString styleSheet = QLatin1String(file.readAll());
      			qApp->setStyleSheet(styleSheet);
      		}
      	}
      }
      

      I have also taken a closer look at the code. I have a qwhatsthis.h and qwhatsthis.cpp file in my Qt source directory. The header file containts a QWhatsThis class declaration. But the source file contains some other declarations and implementations, among others a QWhatsThat class that inherits QWidget.

      I've tried applying a style in my stylesheet file to QWhatsThat instead of QWhatsThis but with no change.

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #8

        For test, can you try with QWidget as specifier and see if
        QWhatsThis is affected at all.

        One should think its at least child of the app and should be affected

        Best part is that doc says
        "If you specify a rich text formatted string, it will be rendered using the default stylesheet"

        So clearly stylesheets should work/it knows about it.

        Update:
        If using no tags, so ALL widgets are colored in whole app, the WhatisThat is not affected.
        So either is not a widget or the window is not attached to the app and hence not using its style or
        it uses a stylesheet internally and override any globals.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #9

          I actually tried to format the QString I'm setting into the widget like this:

          QString help = QString(tr("<span stlye=\"padding: 3px; border-radius: 5px; border: 1px solid rgb(64,255,0), background: rgb(255,255,127); color: rgb(67, 67, 67)\">Test</span>"));
          setWhatsThis(help)
          

          However, it did not have any effect.

          I do have a style for QWidget and that's also not affecting the QWhatsThis.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #10

            I also tried it.
            Nothing affects it. :)

            I looked in
            QWhatsThat::paintEvent(QPaintEvent*)

            Its not using any Styles to draw it and hence cannot be affected as it is not really using the QStyle.
            At least that is how i read it.

            It does use palette.
            p.setPen(QPen(palette().toolTipText(), 0));
            p.setBrush(palette().toolTipBase());

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #11

              Ok
              so palette will affect it
              QApplication a(argc, argv);
              QPalette p = a.palette();
              p.setColor(QPalette::ColorRole::ToolTipBase, Qt::red);
              a.setPalette(p);

              does color background red.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #12

                Ah okay. Not really what I am after, the idea is to load different stylesheets and apply them at runtime of the software. But if that's the only way to get the tip look decent, I guess it's what I'll do.

                Thanks a lot @mrjj

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #13

                  Well its a bit odd it is not made like Tooltip and respect stylesheets.
                  You can change text color and background color with palette and the drop shadow also seems to use palette entries.

                  you can use palette in stylesheets like
                  "background-color : palette(light)"

                  but not seen a syntax to set the palette from inside so not sure there is any good path for
                  use stylesheets with WhatIsThat, unless you steal/reuse the css parser and
                  use it to extract color values and then set the palette for the WhatIS widget.
                  (if you need it truly dynamic)

                  Np. it was interesting case :)

                  Also , i might be wrong :) but in other widgets there is lots of
                  QStyle->draw etc
                  and WhatIsThat seems to use nothing of that so I assume its the real reason why nothing happens with stylesheets.

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #14

                    I agree, it seems like an oversight and I'm going to write an email to support and ask them about it. In the meantime I just use palette. It's not a huge deal with respect to the whole project but I hate when a logical structure behind an architecture has to be altered because of stuff like this.

                    mrjjM 1 Reply Last reply
                    0
                    • ? A Former User

                      I agree, it seems like an oversight and I'm going to write an email to support and ask them about it. In the meantime I just use palette. It's not a huge deal with respect to the whole project but I hate when a logical structure behind an architecture has to be altered because of stuff like this.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #15

                      @tobiSF
                      Sounds like a good plan. Would be great to know the exact details.
                      I do understand its far from optimal to have one window that do not
                      use same styling system as all the rest.

                      It seems not possible to subclass and replace the widget without resort to event filters and
                      some amount of copy pasting code from the original widget.
                      I mean something like qApp()->setWhatisWidget(xx)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved