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. QToolTip and QLineEdit
Forum Updated to NodeBB v4.3 + New Features

QToolTip and QLineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 452 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.
  • G Online
    G Online
    gabello306
    wrote on last edited by
    #1

    I am having using QLineEdit and QToolTip. Based upon certain conditions I need to change the background color of the tool tip to red. I have tried using setStyleSheet as below:

    m_pGlobal->LaunchPage.latitudeSecVal->setStyleSheet("QLineEdit { color: black; background-color: lightgray; }");
    m_pGlobal->LaunchPage.latitudeSecVal->setStyleSheet("QToolTip { color: white; background-color: red; }");
    

    and the tooltip works but the QLineEdit style is changed. The background color is picked up from the parent.

    I also tried using a QPalette as below:

    QPalette palette = QToolTip::palette();
    palette.setColor(QPalette::ToolTipBase, Qt::red);
    palette.setColor(QPalette::ToolTipText, Qt::white);
    QToolTip::setPalette(palette);
    

    Using this doesn't affect the style of the QLineEdit but background color of the ToolTipBase should be red but it is not there. The text is the right color.

    Is there something else I haven't tried?

    1 Reply Last reply
    0
    • G Online
      G Online
      gabello306
      wrote on last edited by
      #3

      I have found a solution to my problem. I use CSS in my styleSheet to figure this out. I have posted the style sheet below.

      QLineEdit  { color: black; background-color: lightgray;}
      QToolTip { border: 0px; background-color: black; color: white;}
      QLineEdit[cssClass~="error"] { border: 2px solid red; background-color: lightgray; color: black; }
      QLineEdit[cssClass~="error"] QToolTip { border: 0px; background-color: red; color: white;}
      

      I then set the Property if the item in question. Setting the cssClass for an error or blank for plain.

      line->setProperty ( "cssClass", "error" );
      
      

      or

      line->setProperty ( "cssClass", "" );
      
      JonBJ 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        For the palette case, the style used can ignore it to ensure the application follows the OS standard.

        As for the stylesheet, one issue is that the second call replaces what you set with the first one.
        You need to set one stylesheet that contains all the changes you want to apply to that widget.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • G Online
          G Online
          gabello306
          wrote on last edited by
          #3

          I have found a solution to my problem. I use CSS in my styleSheet to figure this out. I have posted the style sheet below.

          QLineEdit  { color: black; background-color: lightgray;}
          QToolTip { border: 0px; background-color: black; color: white;}
          QLineEdit[cssClass~="error"] { border: 2px solid red; background-color: lightgray; color: black; }
          QLineEdit[cssClass~="error"] QToolTip { border: 0px; background-color: red; color: white;}
          

          I then set the Property if the item in question. Setting the cssClass for an error or blank for plain.

          line->setProperty ( "cssClass", "error" );
          
          

          or

          line->setProperty ( "cssClass", "" );
          
          JonBJ 1 Reply Last reply
          1
          • G gabello306 has marked this topic as solved on
          • G gabello306

            I have found a solution to my problem. I use CSS in my styleSheet to figure this out. I have posted the style sheet below.

            QLineEdit  { color: black; background-color: lightgray;}
            QToolTip { border: 0px; background-color: black; color: white;}
            QLineEdit[cssClass~="error"] { border: 2px solid red; background-color: lightgray; color: black; }
            QLineEdit[cssClass~="error"] QToolTip { border: 0px; background-color: red; color: white;}
            

            I then set the Property if the item in question. Setting the cssClass for an error or blank for plain.

            line->setProperty ( "cssClass", "error" );
            
            

            or

            line->setProperty ( "cssClass", "" );
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @gabello306
            Don't forget you should polish the style after this dynamic setProperty() change. QStyle::unpolish()/polish(), QWidget::ensurePolished(). Else it may not update immediately.

            1 Reply Last reply
            1

            • Login

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