Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QColorDialog on clicking cancel is by default taking black color.

    General and Desktop
    2
    4
    977
    Loading More Posts
    • 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.
    • S
      Sriu1 last edited by

      color dialog when clicked cancel is taking black instead of taking the previous color.Below is the code.please suggest

      QColorDialog *qcolor = new QColorDialog (this);
      QColor color = qcolor->getColor();
      backgroundcolor = new QColor (color);

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Sriu1 last edited by jsulm

        @Sriu1 "The dialog is a child of parent. It returns an invalid (see QColor::isValid()) color if the user cancels the dialog." - http://doc.qt.io/qt-5/qcolordialog.html#getColor
        Also getColor() is a static method there is no need to create an instance (and it can't have "previos color" for that reason).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 3
        • S
          Sriu1 last edited by

          @jsulm
          I tried if(color.isValid()) ,but the color is setting to white on cancel clicked.I want previously selected color to be retained instead on taking white or black.

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @Sriu1 last edited by

            @Sriu1 And what does color.isValid() return in your case? There can't be "previous color" as getColor() is a static method.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 2
            • First post
              Last post