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. Restore widget default palette color

Restore widget default palette color

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.4k 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.
  • JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by JonB
    #1

    I start life with widgets whose palette has not been altered, so they are at whatever the "default" is for the windowing system. I dynamically change (text color) like:

        QPalette palette = lineEdit->palette();
        palette.setColor(QPalette::Text, colour);
        lineEdit->setPalette(palette);
    

    At a later date I want to remove/restore it to the original default.

    What is the canonical way to do this? E.g.

    • I don't wish to have to save what the color was before I changed it.
    • I'm not seeing a "restore default color/palette", like say palette.setDefaultColor(QPalette::Text), that's what I thought there would be, is there something?
    • Do I have to do something like create a temporary QLineEdit to access its palette for the color to copy?

    EDIT Ah, I just saw the default QPalette::QPalette() says:

    Constructs a palette object that uses the application's default palette.

    That looks good! I thought it would be an "empty" one.

    Even better, QPalette QApplication::palette(const QWidget *widget), https://doc.qt.io/qt-5/qapplication.html#palette

    If a widget is passed, the default palette for the widget's class is returned. This may or may not be the application palette.

    So I think have answered my question, that's what I should use with my widget type to get back the original default color value to reset, right?

    JonBJ 1 Reply Last reply
    0
    • JonBJ JonB

      I start life with widgets whose palette has not been altered, so they are at whatever the "default" is for the windowing system. I dynamically change (text color) like:

          QPalette palette = lineEdit->palette();
          palette.setColor(QPalette::Text, colour);
          lineEdit->setPalette(palette);
      

      At a later date I want to remove/restore it to the original default.

      What is the canonical way to do this? E.g.

      • I don't wish to have to save what the color was before I changed it.
      • I'm not seeing a "restore default color/palette", like say palette.setDefaultColor(QPalette::Text), that's what I thought there would be, is there something?
      • Do I have to do something like create a temporary QLineEdit to access its palette for the color to copy?

      EDIT Ah, I just saw the default QPalette::QPalette() says:

      Constructs a palette object that uses the application's default palette.

      That looks good! I thought it would be an "empty" one.

      Even better, QPalette QApplication::palette(const QWidget *widget), https://doc.qt.io/qt-5/qapplication.html#palette

      If a widget is passed, the default palette for the widget's class is returned. This may or may not be the application palette.

      So I think have answered my question, that's what I should use with my widget type to get back the original default color value to reset, right?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #3

      Even better, QPalette QApplication::palette(const QWidget *widget), https://doc.qt.io/qt-5/qapplication.html#palette

      If a widget is passed, the default palette for the widget's class is returned. This may or may not be the application palette.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Looks good yes.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • JonBJ JonB

          I start life with widgets whose palette has not been altered, so they are at whatever the "default" is for the windowing system. I dynamically change (text color) like:

              QPalette palette = lineEdit->palette();
              palette.setColor(QPalette::Text, colour);
              lineEdit->setPalette(palette);
          

          At a later date I want to remove/restore it to the original default.

          What is the canonical way to do this? E.g.

          • I don't wish to have to save what the color was before I changed it.
          • I'm not seeing a "restore default color/palette", like say palette.setDefaultColor(QPalette::Text), that's what I thought there would be, is there something?
          • Do I have to do something like create a temporary QLineEdit to access its palette for the color to copy?

          EDIT Ah, I just saw the default QPalette::QPalette() says:

          Constructs a palette object that uses the application's default palette.

          That looks good! I thought it would be an "empty" one.

          Even better, QPalette QApplication::palette(const QWidget *widget), https://doc.qt.io/qt-5/qapplication.html#palette

          If a widget is passed, the default palette for the widget's class is returned. This may or may not be the application palette.

          So I think have answered my question, that's what I should use with my widget type to get back the original default color value to reset, right?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #3

          Even better, QPalette QApplication::palette(const QWidget *widget), https://doc.qt.io/qt-5/qapplication.html#palette

          If a widget is passed, the default palette for the widget's class is returned. This may or may not be the application palette.

          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