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 can I temporarily store QLayout?

How can I temporarily store QLayout?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 448 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
    Aaron Kim
    wrote on 26 Jul 2018, 03:57 last edited by aha_1980
    #1

    0_1532576676181_cap1.png

    "contentWidget" is a widget where contents are rendered. As you can see, initially it has no layout.

    0_1532576783594_cap2.PNG
    This is one of the contents which is rendered in the contentWidget. And it has a layout. (indicated with a red circle)
    This layout is applied to contentWidget everytime a content is rendered in contentWidget.

    My topic is, Every time a content in contentWidget changes, I want to store the content (technically the layout applied to contentWidget which has all widgets in contentWidget as children) temporarily so that it will be just loaded, rather than being created again if I render that content again.
    To achieve it, I must detach the layout from contentWidget lest I get an error message below.

    QLayout: Attempting to add QLayout "" to QWidget "contentWidget", which already has a layout
    

    However, it doesn't work well like I expected.

    delete this->contentWidget->layout()->setParent(nullptr);
    
    QWidget *temp = new QWidget();
    delete this->contentWidget->layout()->setParent(temp);
    

    Those examples make the program crash.
    Why this happens?

    J 1 Reply Last reply 26 Jul 2018, 04:16
    0
    • A Aaron Kim
      26 Jul 2018, 03:57

      0_1532576676181_cap1.png

      "contentWidget" is a widget where contents are rendered. As you can see, initially it has no layout.

      0_1532576783594_cap2.PNG
      This is one of the contents which is rendered in the contentWidget. And it has a layout. (indicated with a red circle)
      This layout is applied to contentWidget everytime a content is rendered in contentWidget.

      My topic is, Every time a content in contentWidget changes, I want to store the content (technically the layout applied to contentWidget which has all widgets in contentWidget as children) temporarily so that it will be just loaded, rather than being created again if I render that content again.
      To achieve it, I must detach the layout from contentWidget lest I get an error message below.

      QLayout: Attempting to add QLayout "" to QWidget "contentWidget", which already has a layout
      

      However, it doesn't work well like I expected.

      delete this->contentWidget->layout()->setParent(nullptr);
      
      QWidget *temp = new QWidget();
      delete this->contentWidget->layout()->setParent(temp);
      

      Those examples make the program crash.
      Why this happens?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 26 Jul 2018, 04:16 last edited by
      #2

      @Aaron-Kim Sounds like http://doc.qt.io/qt-5/qstackedwidget.html is what you need.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Aaron Kim
        wrote on 26 Jul 2018, 04:44 last edited by
        #3

        Thanks. It looks more convenient.

        1 Reply Last reply
        0

        2/3

        26 Jul 2018, 04:16

        • Login

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