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. QScrollArea::takeWidget() with the widget in a QGridLayout
Forum Updated to NodeBB v4.3 + New Features

QScrollArea::takeWidget() with the widget in a QGridLayout

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 566 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    I have a scroll area with a label as a placeholder in a dialog. The scroll area will eventually display a graph in a QSvgWidget, but only when the user clicks a button after possibly changing some parameters.

    The placeholder label is in a grid layout so that it is centered horizontally and vertically on the scroll area's child. I want to save the placeholder widget when I set the SVG widget so that later, if parameters are changed after the graph has been shown once, that I can replace the SVG widget with the placeholder and then re-generate the graph again.

    The docs seem straightforward about it ... if I call QScrollArea::takeWidget(), the caller assumes ownership of the widget returned in the pointer. When I set the widget in the scroll area again, the scroll area assumes ownership. But who (or what) owns the QGridLayout? The SVG widget should not be in a layout because it can be scaled or zoomed, and it will be resized programmatically. If I call takeWidget, does the grid layout come along with it? Or do I need to create it again when I use the placeholder a second time?

    JonBJ 1 Reply Last reply
    0
    • R Robert Hairgrove

      I have a scroll area with a label as a placeholder in a dialog. The scroll area will eventually display a graph in a QSvgWidget, but only when the user clicks a button after possibly changing some parameters.

      The placeholder label is in a grid layout so that it is centered horizontally and vertically on the scroll area's child. I want to save the placeholder widget when I set the SVG widget so that later, if parameters are changed after the graph has been shown once, that I can replace the SVG widget with the placeholder and then re-generate the graph again.

      The docs seem straightforward about it ... if I call QScrollArea::takeWidget(), the caller assumes ownership of the widget returned in the pointer. When I set the widget in the scroll area again, the scroll area assumes ownership. But who (or what) owns the QGridLayout? The SVG widget should not be in a layout because it can be scaled or zoomed, and it will be resized programmatically. If I call takeWidget, does the grid layout come along with it? Or do I need to create it again when I use the placeholder a second time?

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

      @Robert-Hairgrove said in QScrollArea::takeWidget() with the widget in a QGridLayout:

      But who (or what) owns the QGridLayout?

      What was its parent when created?

      If I call takeWidget, does the grid layout come along with it?

      If a widget is owned by another widget, it goes with that widget.

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

        Hi,

        What about a simpler solution ? You can use a QStackedWidget so you just switch between your label and the other widget you want to show.

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

        R 1 Reply Last reply
        1
        • JonBJ JonB

          @Robert-Hairgrove said in QScrollArea::takeWidget() with the widget in a QGridLayout:

          But who (or what) owns the QGridLayout?

          What was its parent when created?

          If I call takeWidget, does the grid layout come along with it?

          If a widget is owned by another widget, it goes with that widget.

          R Offline
          R Offline
          Robert Hairgrove
          wrote on last edited by
          #4

          @JonB -- Thank you, you have answered my question perfectly! My ui_ header file tells me that the grid layout is indeed owned by the child widget of the scroll area. So it shouldn't be a problem.

          But @SGaist has given me another good idea which will be simpler to implement and clearer for those following me to understand what is happening here. I will give that a try.

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            What about a simpler solution ? You can use a QStackedWidget so you just switch between your label and the other widget you want to show.

            R Offline
            R Offline
            Robert Hairgrove
            wrote on last edited by
            #5

            @SGaist -- thank you! This seems like a better solution, although @JonB has given me a good answer. I shall try your suggestion, because it is clearer for those people who will eventually have to maintain my code.

            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