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. [SOLVED] Change the Layout/Content of a QWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Change the Layout/Content of a QWidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.5k Views 1 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.
  • S Offline
    S Offline
    sayezz
    wrote on last edited by
    #1

    Hey, look at this picture:
    !http://luna-arts.de/others/misc/ui.png(ui)!

    I have two lists with several Elements. Each Element has a .ui File (blue lines) with different content. Each of the .ui files has a QWidget, having a QVBoxLayout, storing the content (e.g. Labels and QImages, etc).

    Now, if I click one of the Elements in the QListView, I would like to load the content of the elements .ui files in to the main widget on the left side (green arrows).

    I can use:
    @
    mainWidget->setLayout(element0->getVBoxLayout());
    @
    but this works only one time, the content won't refresh and I always see the content of element0.

    I can use
    @
    mainWidget->removeLayout(..);
    mainWidget->setLayout(element0->getVBoxLayout());
    @
    but then I can always click only one time each element. After that I get a Segmentation Fault because I have deleted the content of the Element. But it should be possible to click always each element in the two lists and the content should always change.

    Any idea how to achviev that=

    Thanks
    Regards
    Denis

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Soraltan
      wrote on last edited by
      #2

      Hi,

      wouldn't it be easier to just add the widgets on the left side to the layout of the right side widget and alway have only one of the "visible":http://qt-project.org/doc/qt-4.8/qwidget.html#visible-prop?

      If you don't want top do that for some reason, I would set a fixed QHBoxlayout tot he right side widget. Then I would add an entire elementx widget(s) to that layout of the right side widget. If another elementx widget should be displayed you just "remove":http://qt-project.org/doc/qt-4.8/qwidget.html#visible-prop the previously added widget and add the new one.

      Moving layouts between widgets ... I have never done that actually. I don't know whether this is possible...

      Best Soraltan

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sayezz
        wrote on last edited by
        #3

        Soraltan you are my hero!

        I was going to get crazy. Almost jumped out of the window while singing "Hit me baby one more time" from Britney Spears.

        At the beginning of my program I load the widget of all elements into the main widget (the widget on the right), hiding all widgets. When clicking on a element I just show it. It works like expected!

        Thanks, thanks, THANKS!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Soraltan
          wrote on last edited by
          #4

          Your welcome. Glad I could save your from such a cruel fate ;-)

          Best Soraltan

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            Hi,
            The show/hide is a perfect option! Would have done the same. What is also possible is not to set/clear the layout, but to add/remove the entire widget of the Mainwindow. You get/set it with the setCentralWidget(). That should work as well.

            Greetz, Jeroen

            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