Results 1 to 15 of 15

Thread: Color ComboBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Color ComboBox

    take a look at this example. I think it should help you.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  2. #2
    Join Date
    Apr 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Color ComboBox

    Thanks for the reply. However, in this case the color only occupies a small rectangle in the left side of the combobox. I would like the color to occupy the whole of the combobox.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Color ComboBox

    try this
    Qt Code:
    1. QComboBox *cb = new QComboBox(this);
    2. const QStringList colorNames = QColor::colorNames();
    3. int index = 0;
    4. foreach (const QString &colorName, colorNames) {
    5. const QColor color(colorName);
    6. cb->addItem(colorName, color);
    7. const QModelIndex idx = cb->model()->index(index++, 0);
    8. cb->model()->setData(idx, color, Qt::BackgroundColorRole);
    9. }
    To copy to clipboard, switch view to plain text mode 
    hope you've got idea.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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
  •  
Qt is a trademark of The Qt Company.