0

I used the answer provided here to give users a signal regarding the quality of their input for a QLineEdit. The trouble is that my QToolTip has incorporated this same style which is not ideal.

Here is the validator

def handleValidationChange(self, state):
    if state == QtGui.QValidator.Invalid:
        colour = 'white'
    elif state == QtGui.QValidator.Intermediate:
        colour = 'yellow'
    elif state == QtGui.QValidator.Acceptable:
        colour = 'lightgreen'
   
    self.nameLineEdit.setStyleSheet('background-color: %s' % colour)
    QtCore.QTimer.singleShot(5000, lambda: self.nameLineEdit.setStyleSheet(''))

Within the app.setStyleSheet I try to make it so the tool tip gets a different style, but it ends up matching the validation style, if I hover over the line-edit while an entry is made.

 app.setStyleSheet('''\
    QToolTip {background-color: lightblue !important;}
    '''
    )

Does anyone know how separate out the line-edit style with the validation from the QToolTip style? In this screen capture, the line-edit, and tool-tip background colors match.

qtooltip matches validation color

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Patty Jula
  • 255
  • 1
  • 12

1 Answers1

2

You must indicate which class (or classes) the stylesheet affects, if not, it is equivalent to using QWidget as a class so it will be applied to all its children and the tooltip.

The solution is:

self.edit.setStyleSheet(
    "QLineEdit{border: 3px solid %s} QToolTip{background-color: lightblue}"
    % colour
)
QtCore.QTimer.singleShot(
    1000,
    lambda: self.edit.setStyleSheet("QToolTip{background-color: lightblue}"),
)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241