Results 1 to 15 of 15

Thread: Color ComboBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Color ComboBox

    I don't modify the model I didn't say my code was better than yours, I have only shown how to make my color combobox display colors in a different way. Many ways may lead to the same result, there is no point in discussing the differences.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Color ComboBox

    Quote Originally Posted by wysota View Post
    I don't modify the model I didn't say my code was better than yours, I have only shown how to make my color combobox display colors in a different way. Many ways may lead to the same result, there is no point in discussing the differences.
    but any way you have to get colors from model
    ok, agree with this "Many ways may lead to the same result".
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Oct 2012
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color ComboBox

    Hi,

    I tried the spirit's idea. It works fine for the menu but the selected option does not display the background color.
    How can I put the color in the background of the actual index?

    Thank you very much!

  4. #4
    Join Date
    Oct 2012
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color ComboBox

    When the index changes I need to set the base with the color of the current index:

    Qt Code:
    1. QColor color = qvariant_cast<QColor>(model()->index(index, 0).data(Qt::BackgroundColorRole));
    2.  
    3. QPalette pal = palette();
    4. pal.setColor(QPalette::Base, color);
    5. setPalette(pal);
    To copy to clipboard, switch view to plain text mode 

    This works very well, I have the correct color in the right place... but, the highlight mess it up. I don't need the highlight since I'm working with colors.
    Is there a way to simple remove the highlight?

    I had tried this:

    Qt Code:
    1. pal.setColor(QPalette::Highlight, Qt::transparent);
    To copy to clipboard, switch view to plain text mode 

    but it's not transparent, it's white.

  5. #5
    Join Date
    Oct 2012
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color ComboBox

    I did a workaround. The idea was make the highlight with the same color of the item.

    Connect the highlighted signal from QComboBox:

    Qt Code:
    1. ComboBoxColor( QWidget *parent = 0 ) : QComboBox( parent )
    2. {
    3. connect( this, SIGNAL(highlighted(int)), this, SLOT(slotHighlight(int)) );
    4. }
    To copy to clipboard, switch view to plain text mode 

    The slot will set the correct color for the current item:

    Qt Code:
    1. void ComboBoxColor::slotHighlight(int index)
    2. {
    3. const QStringList colorNames = QColor::colorNames();
    4. QColor color(colorNames.at(index));
    5.  
    6. QPalette palette = this->palette();
    7. palette.setColor(QPalette::Highlight, color);
    8. setPalette(palette);
    9. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Mar 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Color ComboBox

    spirit

    Default Re: Color ComboBox
    take a look at this example. I think it should help you.

    plzzzzzzzzzzz any body sent me that code iam in deep need to it

    whin i open the above link it dosnt open

  7. #7
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    518
    Thanks
    13
    Thanked 77 Times in 75 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Color ComboBox


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.