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. make visible 1 layout at a time
Forum Updated to NodeBB v4.3 + New Features

make visible 1 layout at a time

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 722 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.
  • B Offline
    B Offline
    benamiar
    wrote on last edited by
    #1

    hello qt community,
    i'm trying to make visible one layout at a time, i want something like the program bellow but with layouts

    QStackedLayout* stackedwidget= new QStackedLayout();
     stackedwidget->addwidget(widget1);// the stackedlayout dispalayed ;
        stackedwidget->addwidget(widget2);// the stackedlayout;
        stackedwidget->setCurrentwidget(widget1);
    
    

    i used the additem and setcurrentindex but i have a message said that QStackedLayout::addItem: Only widgets can be added

    so i'm wondering if someone had this problem before, i need help please

    thanks again ..

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      And you are 10.000% sure that it was indeed a
      QWidget you tried to insert?

      in any case, the sample from the docs works without any warnings
      and i could not make it say
      "QStackedLayout::addItem: Only widgets can be added"

              QWidget *firstPageWidget = new QWidget;
              QWidget *secondPageWidget = new QWidget;
              QWidget *thirdPageWidget = new QWidget;
      
              QStackedLayout *stackedLayout = new QStackedLayout;
              stackedLayout->addWidget(firstPageWidget);
              stackedLayout->addWidget(secondPageWidget);
              stackedLayout->addWidget(thirdPageWidget);
      
              QVBoxLayout *mainLayout = new QVBoxLayout;
              mainLayout->addLayout(stackedLayout);
              centralWidget()->setLayout(mainLayout);
      

      So if you can make it say so, please show the actual code with all definitions.
      and also please mention Qt version , you are using.

      Also, just as a note. There is also QStacketWidget that often is easier to use than
      the raw QStackedLayout.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        benamiar
        wrote on last edited by
        #3

        ow sorry i'm using Qt5.

        i think you didn't read the question well or that i wasn't clear enough :p , i'm trying to have one layout at a time and not one widget at a time it's mean that instead of inserting a widget in a stackedwidget i want to insert layouts. and use one layout at a time.

        i know that their is a qstacked widget but i thought that qstacked layout would allow me to stack layouts which is not the case :).

        thanks again

        mrjjM 1 Reply Last reply
        0
        • B benamiar

          ow sorry i'm using Qt5.

          i think you didn't read the question well or that i wasn't clear enough :p , i'm trying to have one layout at a time and not one widget at a time it's mean that instead of inserting a widget in a stackedwidget i want to insert layouts. and use one layout at a time.

          i know that their is a qstacked widget but i thought that qstacked layout would allow me to stack layouts which is not the case :).

          thanks again

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @benamiar
          Hi,
          i think its me that didnt read it well :)
          On second read, i see you want layouts.

          It won't accept layouts. (AFAIK)
          However, just use a widget, put the wanted layout on that and use it that way.
          The Widget is transparent so should not matter.

          Ah. yes. stacked layout kinda sounds like layouts in a stack indeed :)

          1 Reply Last reply
          2
          • B Offline
            B Offline
            benamiar
            wrote on last edited by
            #5

            i didn't understand what your trying to say so you suggest to put a layout on widget ?

            it won't even compile we can't convert a lyout to a widget, perhaps a widget can be converted to a layout but not the reverse.

            J.HilkJ 1 Reply Last reply
            0
            • B benamiar

              i didn't understand what your trying to say so you suggest to put a layout on widget ?

              it won't even compile we can't convert a lyout to a widget, perhaps a widget can be converted to a layout but not the reverse.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @benamiar the idea is to create a new QWidget, assign it your Layout, and than add it to the QStacledWidget


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              B 1 Reply Last reply
              1
              • J.HilkJ J.Hilk

                @benamiar the idea is to create a new QWidget, assign it your Layout, and than add it to the QStacledWidget

                B Offline
                B Offline
                benamiar
                wrote on last edited by
                #7

                @j-hilk assign a layout to a widget ? how is that even possible? you can add a widget to a layout but a layout to a widget? i'm lost ?

                jsulmJ J.HilkJ 2 Replies Last reply
                0
                • B benamiar

                  @j-hilk assign a layout to a widget ? how is that even possible? you can add a widget to a layout but a layout to a widget? i'm lost ?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @benamiar ?
                  https://doc.qt.io/qt-5/qwidget.html#setLayout
                  A layout isn't just somewhere in the air it is on a widget.

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

                  1 Reply Last reply
                  4
                  • B benamiar

                    @j-hilk assign a layout to a widget ? how is that even possible? you can add a widget to a layout but a layout to a widget? i'm lost ?

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by J.Hilk
                    #9

                    @benamiar a fanction of every QWidget based widget

                    https://doc.qt.io/qt-5/qwidget.html#setLayout


                    edit: ninja sniped by @jsulm 😆


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    B 1 Reply Last reply
                    3
                    • J.HilkJ J.Hilk

                      @benamiar a fanction of every QWidget based widget

                      https://doc.qt.io/qt-5/qwidget.html#setLayout


                      edit: ninja sniped by @jsulm 😆

                      B Offline
                      B Offline
                      benamiar
                      wrote on last edited by
                      #10

                      @j-hilk thanks guys it's working

                      1 Reply Last reply
                      1

                      • Login

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