Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved make visible 1 layout at a time

    General and Desktop
    4
    10
    206
    Loading More Posts
    • 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
      benamiar last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • B
          benamiar last edited by

          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

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @benamiar last edited by mrjj

            @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 Reply Quote 2
            • B
              benamiar last edited by

              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.Hilk 1 Reply Last reply Reply Quote 0
              • J.Hilk
                J.Hilk Moderators @benamiar last edited by

                @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

                Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                B 1 Reply Last reply Reply Quote 1
                • B
                  benamiar @J.Hilk last edited by

                  @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 ?

                  jsulm J.Hilk 2 Replies Last reply Reply Quote 0
                  • jsulm
                    jsulm Lifetime Qt Champion @benamiar last edited by

                    @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 Reply Quote 4
                    • J.Hilk
                      J.Hilk Moderators @benamiar last edited by J.Hilk

                      @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

                      Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                      B 1 Reply Last reply Reply Quote 3
                      • B
                        benamiar @J.Hilk last edited by

                        @j-hilk thanks guys it's working

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post