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

Restore widget default palette color

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.9k 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.
  • J Offline
    J Offline
    JonB
    wrote on 4 Apr 2020, 12:13 last edited by JonB 4 Apr 2020, 12:26
    #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?

    J 1 Reply Last reply 5 Apr 2020, 07:07
    0
    • J JonB
      4 Apr 2020, 12:13

      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?

      J Offline
      J Offline
      JonB
      wrote on 5 Apr 2020, 07:07 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
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 4 Apr 2020, 18:57 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
        • J JonB
          4 Apr 2020, 12:13

          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?

          J Offline
          J Offline
          JonB
          wrote on 5 Apr 2020, 07:07 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

          1/3

          4 Apr 2020, 12:13

          • Login

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