Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What kind of widget to show selected color?

What kind of widget to show selected color?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike54703
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Chris HennesC Offline
      Chris HennesC Offline
      Chris Hennes
      wrote on last edited by
      #2

      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.

      Chris Hennes, Pioneer Library System

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        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.

        • No it's not just for KDE linux
        • it's very easy to compile with CMake

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • M Offline
          M Offline
          Mike54703
          wrote on last edited by Mike54703
          #4

          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.

          VRoninV 1 Reply Last reply
          0
          • M Offline
            M Offline
            Mike54703
            wrote on last edited by
            #5

            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);
            
            1 Reply Last reply
            0
            • M Mike54703

              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.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @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

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved