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. PyQt: QCombobox background text color not reflected in selected state
Forum Updated to NodeBB v4.3 + New Features

PyQt: QCombobox background text color not reflected in selected state

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.6k 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.
  • P Offline
    P Offline
    pyqt_dev2
    wrote on last edited by
    #1

    Hi guys

    The following code works but doesn't do in full what exactly is needed:

    @nameList = ('John','Tom','Henry','Michelle','Ashish','Jo-Huang', ...)
    colorNameList = ('Michelle','Jennifer','Claudia','JimSung', ...)
    callBackObj.NameComboBox.clear()
    callBackObj.NameComboBox.addItem(QString('Account Names'))
    model = callBackObj.NameComboBox.model()
    for name in nameList:
    item = PyQt4.QtGui.QStandardItem(str(account))
    if name in colorNameList:
    item.setBackground(PyQt4.QtGui.QColor('red'))
    model.appedRow(item)@

    Now whenever I expand and view the dropdown, the names in colorNameList appear in red background. So far so good. However when I select one of these red-background names they do not show as red-background when left selected.

    Any ideas how I can ensure that on selection red items appear red and non-red appears non-red.

    Many thanks!

    Rahul

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Just to be sure I understand you correctly: you would like the selection highlight to be in a color similar to the background color ?

      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
      • P Offline
        P Offline
        pyqt_dev2
        wrote on last edited by
        #3

        Hi SGaist

        Thanks for your message and welcome.

        Yes, so I want selection highlight background to have the same background color as it had when it was in not selected state.

        To elaborate consider the following example that comboBox has following 3 entries:

        <NoBackgroundColor>John</NoBackgroundColor>
        <NoBackgroundColor>Henry</NoBackgroundColor>
        <REDBackgroundColor>Michelle</REDBackgroundColor>

        Now when I select John OR Henry, the selected state with dropdown showing either of these values will have no background color; that is fine and expected. However on selecting Michelle the Red background is lost and it switches to No background color. I want it to retain its background Red color in selected state.

        Thanks again
        Rahul

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you should implement a custom QStyledItemDelegate and update the color of the rectangle with the state is selected

          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

          • Login

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