Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt6. How do you change a view?
Forum Updated to NodeBB v4.3 + New Features

Qt6. How do you change a view?

Scheduled Pinned Locked Moved Unsolved Qt 6
3 Posts 3 Posters 586 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.
  • K Offline
    K Offline
    kimjohn
    wrote on last edited by
    #1

    When the current application runs, a window appears which uses a QVBoxLayout. This layout includes two sub layouts. Using a menu or using a button in one of layout, I would like to change the view. The first layout need not change, but the second layout which is a QGridLayout need to change.
    I tried the followings.

    1. I tried to remove the layout and add a new layout. I could not find the correct way to do this.
    2. I tried closing the window, deleting the view, and then re-constructing view with the change I need. It works sometimes but sometimes it crashes with segmentation fault.
      What is the correct way to change the view in Qt6? In Qt Creator, the view changes when Edit, Debug are selected in the side-bar. I would like to do similar thing.
    JonBJ 1 Reply Last reply
    0
    • K kimjohn

      When the current application runs, a window appears which uses a QVBoxLayout. This layout includes two sub layouts. Using a menu or using a button in one of layout, I would like to change the view. The first layout need not change, but the second layout which is a QGridLayout need to change.
      I tried the followings.

      1. I tried to remove the layout and add a new layout. I could not find the correct way to do this.
      2. I tried closing the window, deleting the view, and then re-constructing view with the change I need. It works sometimes but sometimes it crashes with segmentation fault.
        What is the correct way to change the view in Qt6? In Qt Creator, the view changes when Edit, Debug are selected in the side-bar. I would like to do similar thing.
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @kimjohn
      Hello and welcome.

      It is hard to comment without your attempted code. However if you really want to change from one layout to another the correct way is to remove the existing layout from the widget it is on and then set the new layout on that widget. You would then need to move any widgets on the original layout to the new layout if you wish to retain them.

      However. I do not know what exactly you have in mind by " In Qt Creator, the view changes when Edit, Debug are selected in the side-bar.". But if you want to change between two quite different layouts/views with their own widgets: rather than changing the layout, it is more usual to create a QStackedWidget. That allows you to design two quite different widgets, with their own layouts and their own sub-widgets on those layouts, and to swap between which one of the two is shown to the user at any time.

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

        Hi and welcome to devnet,

        Beside the good recommendation of @JonB, you can also consider the direct use of QStackedLayout in which QStackedWidget is built on.

        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

        • Login

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