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. Initialization of QPalette.
Forum Updated to NodeBB v4.3 + New Features

Initialization of QPalette.

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 265 Views 2 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.
  • ankit thakarA Offline
    ankit thakarA Offline
    ankit thakar
    wrote on last edited by ankit thakar
    #1

    Hello team,

    I was going through demo code of QPalette. Below is the code.
    QColor color = QColorDialog::getColor(QColor(m_label->text()),this,"Select color",QColorDialog::ShowAlphaChannel);
    if(color.isValid())
    {
    QPalette palette = m_label->palette();
    palette.setColor(QPalette::Window,color);
    m_label->setPalette(palette);
    m_label->setText(color.name());
    }

    Now instead of initializing QPalette like this QPalette palette = m_label->palette();
    if I do like this,
    QPalette palette;
    palette.setColor(QPalette::Window,color);
    m_label->setPalette(palette);
    m_label->setText(color.name());

    What is the difference in both initialization?

    Pl45m4P 1 Reply Last reply
    0
    • ankit thakarA ankit thakar

      Hello team,

      I was going through demo code of QPalette. Below is the code.
      QColor color = QColorDialog::getColor(QColor(m_label->text()),this,"Select color",QColorDialog::ShowAlphaChannel);
      if(color.isValid())
      {
      QPalette palette = m_label->palette();
      palette.setColor(QPalette::Window,color);
      m_label->setPalette(palette);
      m_label->setText(color.name());
      }

      Now instead of initializing QPalette like this QPalette palette = m_label->palette();
      if I do like this,
      QPalette palette;
      palette.setColor(QPalette::Window,color);
      m_label->setPalette(palette);
      m_label->setText(color.name());

      What is the difference in both initialization?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @ankit-thakar said in Initialization of QPalette.:

      What is the difference in both initialization?

      The first one grabs the current palette from m_label , sets the color to color and sets the edited palette to the label again.
      Everything else will be the same as m_labels palette.

      The second one creates a new palette with default parameters and color color (No additional brush, shadow or anything else)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      4

      • Login

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