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. QColorDialog on clicking cancel is by default taking black color.
Forum Updated to NodeBB v4.3 + New Features

QColorDialog on clicking cancel is by default taking black color.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.4k Views
  • 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 Offline
    S Offline
    Sriu1
    wrote on last edited by
    #1

    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);

    jsulmJ 1 Reply Last reply
    0
    • S Sriu1

      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);

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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
      3
      • S Offline
        S Offline
        Sriu1
        wrote on last edited by
        #3

        @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.

        jsulmJ 1 Reply Last reply
        0
        • S Sriu1

          @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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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
          2

          • Login

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