What kind of widget to show selected color?



  • I want to used the color dialog to let the use select a color - but in the window from which that dialog is called I want to have something show the use what color they selected... some sort of widget I would presume. This would be very similar to what is done in the color dialog where it shows the current and new color.

    And then how does one set the color of this 'widget' ?

    Thanks.



  • I'd think just a button with a pixmap in it would be the easiest. Paint your color into the pixmap and you've got your widget.



  • KColorButton

    If this is all you need you can just copy the source from the bottom of the link and paste it in your project, just remove KWIDGETSADDONS_EXPORT and #include <kwidgetsaddons_export.h> from the header file. No need to compile the whole module.



  • A button with a pixmap seems like a round about method - needs a pixmap to start with.

    I don't care for the KColorButton....

    Just seems like this should be an easy answer for this... kind of basic I would think.



  • Found it! fg_color is my label widget

    static QColor fg = Qt::blue;
    
    fg = QColorDialog::getColor(fg, this, "Foreground Color");
    
    ui->fg_color->setAutoFillBackground(true);
    QPalette pal = ui->fg_color->palette();
    pal.setColor(QPalette::Window, fg);
    ui->fg_color->setPalette(pal);


  • @Mike54703 said in What kind of widget to show selected color?:

    I don't care for the KColorButton....
    Just seems like this should be an easy answer for this... kind of basic I would think.

    I can't think of anything easier than copy/pasting a source code. but this is just my opinion


Log in to reply