Results 1 to 5 of 5

Thread: Qt5/C++ - QComboBox - change currrent text color and the dropdown text colour

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qt5/C++ - QComboBox - change currrent text color and the dropdown text colour

    Qt Creator 3.6.1 - Based on Qt 5.6.0 (MSVC 2013, 32 bit) - Windows 10

    Hello,

    Qt Code:
    1. qApp->setStyleSheet("QGroupBox, QComboBox, QRadioButton, QPushButton, QLabel, QLineEdit"
    2. "{ color: blue }"); // text colour
    3.  
    4. ui->myComboBox->setStyleSheet("QListView { color: blue; }");
    5. ui->myComboBox->setStyleSheet("QComboBox { background-color: white }");
    To copy to clipboard, switch view to plain text mode 
    I'm trying to set the text colour and the dropdown list text colour on a QComboBox.
    I tried changing the order and it seems that the last setStyleSheet is the one that takes effect.
    How do I apply both to the QComboBox?

    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5/C++ - QComboBox - change currrent text color and the dropdown text colour

    The last two are obviously exclusive, since the stylesheet in line 5 overwrites the one set in line 4.

    Are you saying that the rule set in line 1 and the rule set in line 5 are not both active?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5/C++ - QComboBox - change currrent text color and the dropdown text colour

    Hello anda_skoa,

    Thanks for your reply,

    The last two are obviously exclusive
    I gathered that from my test.

    I can get lines 1 & 5 working.
    I can get lines 1 & 4 working.

    What I would like to is get line 1 and lines 4 & 5 working together.
    I can't work out the syntax required.

    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5/C++ - QComboBox - change currrent text color and the dropdown text colour

    You need to combine the two strings into one.

    Two calls to a setter function will always result in the second value being the current value.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    jimbo (19th July 2016)

  6. #5
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5/C++ - QComboBox - change currrent text color and the dropdown text colour

    Hello,

    Many thanks, this seems to work.

    Qt Code:
    1. ui->myComboBox->setStyleSheet("QComboBox { background-color: white }" "QListView { color: blue; }");
    To copy to clipboard, switch view to plain text mode 
    Regards
    Last edited by jimbo; 19th July 2016 at 23:33.

Similar Threads

  1. Replies: 2
    Last Post: 6th September 2011, 06:55
  2. change the text colour in Menubar
    By chinmayapadhi in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2010, 02:31
  3. Replies: 3
    Last Post: 22nd January 2010, 17:46
  4. How to change Label text colour in Qt designer
    By sudhansu in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2010, 13:31
  5. How to change Text colour in EditText?
    By phillip_Qt in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2008, 09:48

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.