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. How to restore QFrame to its initial/default state
Forum Updated to NodeBB v4.3 + New Features

How to restore QFrame to its initial/default state

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 441 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.
  • A Offline
    A Offline
    Absurd
    wrote on last edited by Absurd
    #1

    I am subclassing a QFrame and I have some data members of my own there.
    Initially, I am customizing the QFrame with some parameters such as:

    myFrame->setFrameShape(QFrame::Panel);
    myFrame->setFrameShadow(QFrame::Raised);
    myFrame->setLineWidth(4);
    ...
    ...
    

    And later I want that QFrame to be customized differently, but I want to do that on a clean slate.

    Is there a way to restore a QFrame back to its default state (shape/shadow/background color/line width/etc...)?
    Something along the lines of

    myFrame->setToDefualt(); // sets MyFrame back to its defaults as if it was just now created with the 'new' operator
    

    of course I could do:

    delete myFrame;
    myFrame = new MyFrame();
    

    but I'd rather avoid that.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Move the lines where you set your default behavior into an own function and call it later on again when you want to reset to default.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        Move the lines where you set your default behavior into an own function and call it later on again when you want to reset to default.

        A Offline
        A Offline
        Absurd
        wrote on last edited by Absurd
        #3

        @Christian-Ehrlicher those lines are in a class ("FormatterA") that customizes the QFrame, and I have another class ("FormatterB") that will customize it differently (and in the future there might be more "Formatters"), but I don't want FormatterB to assume knowledge on FormatterA, I want FormatterB to just do myFrame->setToDefault() to cancel everything that's been done by FormatterA.

        I can write my own myFrame->setToDefault() and have the Formatters invoke it, but that's prone to misses since another formatter in the future might change an attribute that wasn't initialized in myFrame->setToDefault().
        So I thought maybe there's something like that that's provided by the object that I was missing...

        JonBJ 1 Reply Last reply
        0
        • A Absurd

          @Christian-Ehrlicher those lines are in a class ("FormatterA") that customizes the QFrame, and I have another class ("FormatterB") that will customize it differently (and in the future there might be more "Formatters"), but I don't want FormatterB to assume knowledge on FormatterA, I want FormatterB to just do myFrame->setToDefault() to cancel everything that's been done by FormatterA.

          I can write my own myFrame->setToDefault() and have the Formatters invoke it, but that's prone to misses since another formatter in the future might change an attribute that wasn't initialized in myFrame->setToDefault().
          So I thought maybe there's something like that that's provided by the object that I was missing...

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Absurd
          There is no "restore object to default/as it was before FormatterA" call.

          Only FormatterA knows exactly what it did to your object. Either export a method from FormatterA which knows how to reset what it did, or, just possibly, have it save all the original settings somehow in a subclassed QFrame and use those values to restore.

          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