Results 1 to 10 of 10

Thread: Color combobox

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

    Default Color combobox

    Hi,

    I am having some trouble trying to find and/or make a combo box (or something similar) that shows different colors rather than text or numbers. Right now I have a text box and if you type in the HTML color and click ok the font color will change. But I would much rather some kind of combo that displays a couple default colors instead.

    Thanks for the help.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Color combobox

    Why don't you just use QColorDialog?

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color combobox

    Create your own custom QAbstractItemDelegate and QAbstractItem if you want to do complex drawing on the combo items.

    Otherwise just use QComboBox::insertItem and pass an empty string as the first parameter and for the second a QVariant( pix ), where pix should be your pixmap filled with the color you want. Passing an empty string should provide the result you mentioned.

    Marcel

  4. #4
    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

    How about something like this?
    Qt Code:
    1. comboBox->addItem("red");
    2. comboBox->setItemData(0, Qt::red, Qt::BackgroundRole);
    3. comboBox->addItem("green");
    4. comboBox->setItemData(1, Qt::green, Qt::BackgroundRole);
    5. comboBox->addItem("blue");
    6. comboBox->setItemData(2, Qt::blue, Qt::BackgroundRole);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Color combobox

    or on the fly icon ... and all name color from QT...



    Qt Code:
    1. void Interface::populateFilter(QComboBox *comboBox)
    2. {
    3. QPixmap pix(22, 22);
    4.  
    5. QStringList colorNames = QColor::colorNames();
    6. comboBox->addItem(tr("Select a filter.."));
    7. pix.fill(QColor("grey"));
    8. comboBox->addItem(pix,tr("GreyScale"));
    9. comboBox->addItem(tr("RGB Swapped"));
    10. comboBox->addItem(tr("InvertPixels color"));
    11. pix.fill(QColor(162,128,101));
    12. comboBox->addItem(pix,tr("Colorize")+QString(" color=\"sepia\""));
    13. comboBox->addItem(tr("Colorize")+QString(" color=\"mycolor\""));
    14.  
    15. foreach (QString name, colorNames) {
    16.  
    17. pix.fill(QColor(name));
    18. comboBox->addItem(pix,tr("Colorize")+QString(" color=\"%1\"").arg(name));
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Color combobox

    wow, thanks a lot.
    I'll post back if I hve any more problems

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

    Default Re: Color combobox

    I am having one small problem now:
    In the comboBox, when you scroll over the color it changes color because it mixes blue (the highlighter) of the mouse with the color and changes the appearance of the color.
    Is there an easy way to disable that highlighter? or changing it somehow?

    Thanks for the help!

  8. #8
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Color combobox

    Quote Originally Posted by chguy2 View Post
    I am having one small problem now:
    In the comboBox, when you scroll over the color it changes color because it mixes blue (the highlighter) of the mouse with the color and changes the appearance of the color.
    Is there an easy way to disable that highlighter? or changing it somehow?

    Thanks for the help!
    chance palette to white or make a border on color....

    code from http://qt-webdav.svn.sourceforge.net...v/html_editor/
    html editor && image editor from subdir http://sourceforge.net/projects/qt-webdav/




    of topic... is chguy2 indended from switzerland?
    Attached Images Attached Images

  9. #9
    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

    I have a widget that is a combobox that allows to pick colours from a user defined set of options. It'll be published as part of a larger widget set after Easter. So keep your eyes open if you're interested.

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

    Default Re: Color combobox

    I changed the palette to white, but now when I scroll down the colors go from red, blue, green to white when they are highlighted. I also can't find that: Filter apply. I guess its too good to be true. I am using Qt 4.2.2.

    What I am trying to do is just make this one comboBox highlight disabled or set to transparent.

    And sorry Patrik, I am from Canada.
    Last edited by chguy2; 5th April 2007 at 14:35.

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.