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. How to set color in QColorDialog ?
Forum Updated to NodeBB v4.3 + New Features

How to set color in QColorDialog ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 755 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.
  • T Offline
    T Offline
    tushu
    wrote on last edited by tushu
    #1

    I have a QGraphicsScene which has many QGraphicsItem like rectangle, circle, lines etc.
    I am coloring them by invoking color palette ( I have a button for color palette. Once that clicked, following code runs. )

    QColor color = QColorDialog::getColor(Qt::white, this, "Choose Color");
        if (color.isValid()) {
            currentColor = color;
    }
    

    And then I am using "currentColor" to color my QGraphicsItem from scene.
    And at the same time, I am storing "currentColor" in std::map along with the QGraphicsItem which are colored with currentColor.

    What am I trying to solve ?
    When next time I will open QColorDialog, it should scan map, and the color found in map, should be ticked in color dialog ( so that user will understand, which color are used in scene. )
    So how to set color in QColorDialog ?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      What does, "the color found in map, should be ticked in color dialog," mean?

      If you mean that these colours should be loaded in to the "Custom colors" part of the dialog then you use the QColorDialog::setCustomColor() and related functions.

      Similarly, you can use the QColorDialog::setStandardColor() function.

      T 1 Reply Last reply
      0
      • C ChrisW67

        What does, "the color found in map, should be ticked in color dialog," mean?

        If you mean that these colours should be loaded in to the "Custom colors" part of the dialog then you use the QColorDialog::setCustomColor() and related functions.

        Similarly, you can use the QColorDialog::setStandardColor() function.

        T Offline
        T Offline
        tushu
        wrote on last edited by
        #3

        @ChrisW67 Thank you for your reply.
        I am trying to say like this :

        Lets say , I selected "Red" color and color I1 and I2 QGraphicsItem with it.

        Then I selected "Green" color and color I3 and I4 QGraphicsItem with it.

        Then I selected "Yellow" color and color I5 QGraphicsItem with it.

        Then my map entry will be :
        Red - I1, I2
        Green - I3, I4
        Yellow - I5

        So next time when I will open QColorDialog, It should scan map , and read color "Red", "Green" and "Yellow" and mark them in it's palette. So User will know, I have chosen 3 colors.
        Now if user wants to de-highlight one of the color group then he will unticked through QColorDialog. And all the QGraphicsItem colored with that color will be de-highlighted. ( that's a feature I am trying to implement)

        So I want, how to mark color in QColorDialog ?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          There is no such capability in QColorDialog. You may need to implement a dialog yourself or rethink how this "uncolouring" mechanism should work.

          1 Reply Last reply
          1

          • Login

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