Results 1 to 5 of 5

Thread: Problem with QComboBox

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with QComboBox

    Hi friends,
    i tried to change the text color of the QComboBox using QPalette ...

    Qt Code:
    1. comboBox->setAutoFillBackground(true);
    2.  
    3.  
    4. ComboBod::SelectedIndex(int index)
    5. {
    6. QPalette comboPalette = palette();
    7. if(index == 1)
    8. {
    9. comboPalette.setColor(QPalette::Text, Qt::green);
    10. comboPalette.setColor(QPalette::WindowText, Qt::green);
    11. }else
    12. {
    13. comboPalette.setColor = parentWidget()->palette();
    14. }
    15.  
    16. comboBox->setPalette(comboPalette);
    17. }
    To copy to clipboard, switch view to plain text mode 

    but its not reflecting any change in the color ... i tried stylesheets also but not able to change the text of the comboBox .. only selection window text is changing ...

    please hlp me ..

    Thanks in advance
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QComboBox

    Hi wagmare,
    Are you want to change all text color in QComboBox or only selected item?
    I use this command :
    Qt Code:
    1. comboBox->setStyleSheet(QString::fromUtf8("color: rgb(99, 146, 255);"));
    To copy to clipboard, switch view to plain text mode 
    this command will change all text color in QComboBox.

    Best regards,

    Toto

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QComboBox

    thanks myta ...

    i just want to change the text of the ComboBox and not the selection item ... last one u suggested i tried but it changing the selection items ...


    Thanks once again
    "Behind every great fortune lies a crime" - Balzac

  4. #4
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QComboBox

    Hi wagmare,
    You can use "selection-color" stylesheet method like this:
    Qt Code:
    1. ui->comboBox->setStyleSheet("QComboBox { selection-color: black; color : blue; }");
    To copy to clipboard, switch view to plain text mode 
    This method will change all item at QComboBox, but you can change itemselected color like not selected.
    Example :
    default combobox item color = black
    selected comboxbox item color = black
    not selected comboxbox item color = blue

    I think this method can solve your problem. Or we have missunderstanding about your problem ?
    Thank you for your attention.

    Best regards,

    Toto

  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QComboBox

    Once again thanks for replying myta ..
    ui->comboBox->setStyleSheet("QComboBox { selection-color: black; color : blue; }");

    this you try with QComboBox .. it will change the color of the text when u press the QComboBox and shows the DropDown list ..
    i required the text color change in QComboBox after selection had been done ...

    i tried ur code .. as it is changing only the color of the dropdown selection of the comboBox and not the normal text in the comboBox after selecting ...
    EX:after i selects one item in comboBox .. the item name will be displayed in comboBox .. that name should be shown in red color (for a particular item say index =1)...

    Thanks again .....
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. QComboBox Problem
    By UnforgiveNX in forum Qt Programming
    Replies: 0
    Last Post: 18th November 2010, 15:50
  2. QComboBox problem
    By SteveH in forum Newbie
    Replies: 2
    Last Post: 2nd March 2009, 21:20
  3. QComboBox problem
    By ^NyAw^ in forum Qt Programming
    Replies: 4
    Last Post: 31st March 2008, 11:43
  4. Problem while using QComboBox
    By merry in forum Qt Programming
    Replies: 6
    Last Post: 20th December 2007, 10:22
  5. Problem with QComboBox
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 8th December 2007, 13:21

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.