Results 1 to 3 of 3

Thread: color comboBox problem

  1. #1
    Join Date
    Apr 2007
    Posts
    5
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default color comboBox problem

    Hi guys,

    I have a comboBox that displays colors with the last item that displays “other”.

    My code looks like:
    Qt Code:
    1. comboBox_colors->addItem(“”);
    2. comboBox_colors->setItemData(0,Qt::red,Qt::BackgroundColorRole);
    3. comboBox_colors->addItem(“”);
    4. comboBox_colors->setItemData(1,Qt::blue,Qt::BackgroundColorRole);
    5. comboBox_colors->addItem(“”);
    6. comboBox_colors->setItemData(2,Qt::green,Qt::BackgroundColorRole);
    7. …
    8. comboBox_colors->addItem(“other”);
    9. comboBox_colors->setItemData(15,Qt::transparent,Qt::BackgroundColorRole);
    To copy to clipboard, switch view to plain text mode 

    I am having trouble disabling the highlight option because now when I scroll over the colors they change from whatever the color is to the highlight color. I tried changing the highlight color to white but it just changes the color from whatever to white.
    I am also having trouble displaying the selected color in the comboBox when it is minimized. No matter what color is selected it will not display when the comboBox is minimized. So it always has a white background when the comboBox is minimized. The only time when I see something in the comboBox is when “other” is selected because “other” is displayed. Obviously if I put a word in the “” when I add the item, it will get displayed but I want it to display the color and no words.

    If someone could help me out with this, it would be greatly appreciated. I have been suck on this for awhile.


    *Maybe instead of disabling the highlight I can just set it to transparent? How do you change the color of the highlight in a comboBox in code? I only know how to change it using QT designer.*

    I tried:
    Qt Code:
    1. QPalette highlight;
    2. QBrush trans(Qt::transparent);
    3. trans.setStyle(Qt::SolidPattern);
    4. highlight.setBrush(QPalette::Highlight,trans);
    5. comboBox_colors->setPalette(highlight);
    To copy to clipboard, switch view to plain text mode 
    But that makes it white and not transparent.

    Thanks.
    Last edited by chguy2; 20th April 2007 at 16:28.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: color comboBox problem

    I'm not convinced changing the palette like that is a good idea. How would you see the selection at all?

    Anyway, after taking a look at qitemdelegate.cpp I noticed that also a color is supported as decoration role (I'm not sure since when, but presumably at least in 4.2). So here's yet another proposal in addition to those in thread Color combobox:
    Qt Code:
    1. comboBox->addItem("red");
    2. comboBox->setItemData(0, QColor(Qt::red), Qt::DecorationRole);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    Default Re: color comboBox problem

    Quote Originally Posted by jpn View Post
    color is supported as decoration role (I'm not sure since when, but presumably at least in 4.2).
    AFAIR Since 4.0

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.