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. replace one widget with another on a layout with a button
QtWS25 Last Chance

replace one widget with another on a layout with a button

Scheduled Pinned Locked Moved General and Desktop
c++linuxqpushbuttonqscrollareaqgroupbox
11 Posts 3 Posters 8.1k Views
  • 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi
    Is that the actual code ?

    videoChart = new QGroupBox;

    but you add
    addWidget(charts,0,Qt::AlignHCenter);

    and what is startTest->clicked() ?

    M 1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      Is that the actual code ?

      videoChart = new QGroupBox;

      but you add
      addWidget(charts,0,Qt::AlignHCenter);

      and what is startTest->clicked() ?

      M Offline
      M Offline
      marlenet15
      wrote on last edited by marlenet15
      #3

      @mrjj when I press that button, i would like for the charts to replace the QScrollArea that is there right now. And that is not the whole whole code that it is the section I am trying to say when I click this button replace this with this

      mrjjM 1 Reply Last reply
      0
      • M marlenet15

        @mrjj when I press that button, i would like for the charts to replace the QScrollArea that is there right now. And that is not the whole whole code that it is the section I am trying to say when I click this button replace this with this

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

        @marlenet15

        Hi. I understand what you want to happen, but code seems
        strange. (to me)

        the
        if(startTest->clicked())

        Confused me a bit if startTest is a button. ?

        the "clicked" is a signal and should be connected to a slot that will
        be called when the buttons is clicked.
        calling it directly will not work.

        Please place a QPushbutton on the form, then right click it and
        select Go to Slot, then select released().
        you will then go to a function.
        Put you code here.

        you can also connect stuff in code:
        http://doc.qt.io/qt-5/signalsandslots.html

        1 Reply Last reply
        0
        • M Offline
          M Offline
          marlenet15
          wrote on last edited by marlenet15
          #5

          I have created everything from scratch so nothing is in the ui file. I have tried using SIGNAL and SLOTS but it didn't seem to recognize the widgets I wanted to replace

          mrjjM 1 Reply Last reply
          0
          • M marlenet15

            I have created everything from scratch so nothing is in the ui file. I have tried using SIGNAL and SLOTS but it didn't seem to recognize the widgets I wanted to replace

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

            @marlenet15
            well in the sample you call the groupbox for videoChart
            but in the addwidget you have "charts" ?
            I would expect it to be videoChart ?

            Well lets assume you replace function is called
            ReplaceNow and lives in mainwindow
            and your button is called startTest
            then you should have to have a statement like

            connect( startTest, SIGNAL(clicked()), this, SLOT(ReplaceNow()));

            for the button to do anything when clicked.
            Not sure if that is your issue ?

            M 1 Reply Last reply
            0
            • mrjjM mrjj

              @marlenet15
              well in the sample you call the groupbox for videoChart
              but in the addwidget you have "charts" ?
              I would expect it to be videoChart ?

              Well lets assume you replace function is called
              ReplaceNow and lives in mainwindow
              and your button is called startTest
              then you should have to have a statement like

              connect( startTest, SIGNAL(clicked()), this, SLOT(ReplaceNow()));

              for the button to do anything when clicked.
              Not sure if that is your issue ?

              M Offline
              M Offline
              marlenet15
              wrote on last edited by
              #7

              @mrjj chart is also a QGroupBox which I didn't include in the code. Sorry. Ok so how will it know what exact widgets to replace? That is my question. Would it be something like this?

              void ReplaceNow()
              {
               videoChartLayout->removeWidget(instructionsScrollArea1);
               videoChartLayout->addwidget(charts,0,Qt::AlignHCenter);
              }
              
              mrjjM 1 Reply Last reply
              0
              • M marlenet15

                @mrjj chart is also a QGroupBox which I didn't include in the code. Sorry. Ok so how will it know what exact widgets to replace? That is my question. Would it be something like this?

                void ReplaceNow()
                {
                 videoChartLayout->removeWidget(instructionsScrollArea1);
                 videoChartLayout->addwidget(charts,0,Qt::AlignHCenter);
                }
                
                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @marlenet15
                Ahh. ok.
                yes then you would use the pointer to the widget.
                Like instructionsScrollArea1 if that was the one you used to insert it with in first place?

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

                  Hi,

                  Sounds rather like a job for QStackedLayout

                  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
                  0
                  • mrjjM mrjj

                    @marlenet15
                    Ahh. ok.
                    yes then you would use the pointer to the widget.
                    Like instructionsScrollArea1 if that was the one you used to insert it with in first place?

                    M Offline
                    M Offline
                    marlenet15
                    wrote on last edited by
                    #10

                    @mrjj I did this but it says that the variables are not declared on the scope

                    void ReplaceNow()
                    {
                     *videoChartLayout->removeWidget(*instructionsScrollArea1);
                     *videoChartLayout->addwidget(charts,0,Qt::AlignHCenter);
                    }
                    
                    mrjjM 1 Reply Last reply
                    0
                    • M marlenet15

                      @mrjj I did this but it says that the variables are not declared on the scope

                      void ReplaceNow()
                      {
                       *videoChartLayout->removeWidget(*instructionsScrollArea1);
                       *videoChartLayout->addwidget(charts,0,Qt::AlignHCenter);
                      }
                      
                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #11

                      @marlenet15

                      instructionsScrollArea1 and ReplaceNow() should be
                      in same object or same file at least.

                      that what scope means.

                      so where is instructionsScrollArea1 declared and where
                      is void ReplaceNow() ?

                      Also
                      the * in
                      removeWidget(*instructionsScrollArea1);
                      is wrong.

                      If possible,post whole code here and its easier for us to help.

                      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