Results 1 to 6 of 6

Thread: PyQt: QCombobox background text color not reflected in selected state

  1. #1
    Join Date
    Feb 2015
    Posts
    3
    Qt products
    Platforms
    Windows

    Question PyQt: QCombobox background text color not reflected in selected state

    Hi guys,

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


    Qt Code:
    1. nameList = ('John','Tom','Henry','Michelle','Ashish','Jo-Huang', ...)
    2. colorNameList = ('Michelle','Jennifer','Claudia','JimSung', ...)
    3. callBackObj.NameComboBox.clear()
    4. callBackObj.NameComboBox.addItem(QString('Account Names'))
    5. model = callBackObj.NameComboBox.model()
    6. for name in nameList:
    7. item = PyQt4.QtGui.QStandardItem(str(account))
    8. if name in colorNameList:
    9. item.setBackground(PyQt4.QtGui.QColor('red'))
    10. model.appedRow(item)
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: PyQt: QCombobox background text color not reflected in selected state

    When an entry is selected Qt applies a highlight color on it. You need to alter that as well.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2015
    Posts
    3
    Qt products
    Platforms
    Windows

    Default Re: PyQt: QCombobox background text color not reflected in selected state

    Hi wysota,

    Thanks for your response. However can you advise on how this can be achieve in python. Please refer to the code snippet in my original post above.

    Rahul

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: PyQt: QCombobox background text color not reflected in selected state

    Your original snippet deals with a model while the highlight happens in the view through the delegate. Thus you need to either implement a custom delegate or set the highlight color in your view's palette to transparent.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2015
    Posts
    3
    Qt products
    Platforms
    Windows

    Default Re: PyQt: QCombobox background text color not reflected in selected state

    Hi wysota

    Thanks for your response. I am new to PyQt; would it be possible for you to provide a code snippet to do so.

    Many Thanks
    Rahul

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: PyQt: QCombobox background text color not reflected in selected state

    I am new to PyQt too so we're starting from the same point so you can provide that code snippet yourself as well. You have two hints -- custom delegate and changing the widget's palette.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 10th June 2014, 13:38
  2. QTableView--keep same background color when selected
    By davethomaspilot in forum Qt Programming
    Replies: 0
    Last Post: 11th February 2014, 17:38
  3. Replies: 0
    Last Post: 1st September 2011, 15:20
  4. Replies: 0
    Last Post: 1st November 2010, 08:22
  5. background color of not selected tab
    By iridium in forum Qt Programming
    Replies: 0
    Last Post: 13th August 2009, 15:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.