code: def text_to_qcolor(text):
      
      color = QColor()
      if not is_string(text): # testing for QString (PyQt API#1)
          text = str(text)
      if not is_text_string(text):
          return color
      if text.startswith('#') and len(text)==7:
          correct = '#0123456789abcdef'
          for char in text:
              if char.lower() not in correct:
                  return color
      elif text not in list(QColor.colorNames()):
          return color
      color.setNamedColor(text)
      return color
docs: Create a QColor from specified string
      Avoid warning from Qt when an invalid QColor is instantiated