Qt Forum

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

    Unsolved Qscroll Area eroor

    General and Desktop
    4
    6
    1129
    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.
    • geor
      geor last edited by

      Hello I am having an error with QScrollarea what I am doing in designer is

      1. I create a grid layout and place a couple of widgets in it

      2. a create a random widget and place the layout in it

      3. I give the random widget a layout in grid and same for the main window

      4. in the constructor I create a scrollarea object as such

          QScrollArea* contents = new QScrollArea;
        
         contents->setWidget(ui->widgettest);// widget test is the random widget that contains evrithing
        
         contents->setWidgetResizable(true); 
        

      the output is nothing ....
      this does not work either If I create the scrollarea in designer.
      the only way it works is if I create the random widget by code and the grid layout by code and add each widget created with deisgner as such:

              QWidget * contents = new QWidget;
      
           QGridLayout * layout = new QGridLayout(contents);
      
      
           layout->addWidget(ui->plot,500,600); // evrthing with ui-> is created indesigner
          layout->addWidget(ui->pushButton,700,20);
         layout->addWidget(ui->radioButton);
      
         ui->scrollArea->setWidget(contents);// scroll area is created in deisgner
      
         ui->scrollArea->setWidgetResizable(true);
      

      and the last peace of code is great the only problem is that I have so many widgets and it's a hard to place them all together with the program and much easier with designer.

      So can anyone tell me why is my first method working were I create everything in designer expect scroll area....

      thank you

      raven-worx V 2 Replies Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @geor last edited by

        @geor said:

        Hello I am having an error with QScrollarea what I am doing in designer is

        1. I create a grid layout and place a couple of widgets in it

        2. a create a random widget and place the layout in it

        3. I give the random widget a layout in grid and same for the main window

        4. in the constructor I create a scrollarea object as such

            QScrollArea* contents = new QScrollArea;
          
           contents->setWidget(ui->widgettest);// widget test is the random widget that contains evrithing
          
           contents->setWidgetResizable(true); 
          

        the output is nothing ....

        it sounds like you are not adding the scrollarea widget as a central widget to the main window.
        Or you forgot to call setupUI()?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 1
        • V
          VRonin @geor last edited by

          @geor said:

               QScrollArea* contents = new QScrollArea;
          

          Give the main window as parent to contents and add it as central widget or as part of the layout of the central window.

          To understand better what's going wrong in your code, call contents ->show(); and see what happens

          As a general rule giving a parent to any QObject should be the norm and using NULL parent the exception

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply Reply Quote 1
          • geor
            geor last edited by

            @VRonin @raven-worx . Thank you for both your advice it made it work

            one more thing I am planning on putting 50 widgets and I only want 10 to be visible when the mainwindow is called and the the user scrolls to see the 40 more it's similar to having 5 pages with 10 widget per page only this will be one long page.I am planning on making 5 grid layouts and placing all of them in the main widget witch is in a scroll area. Do you some comments on this? I am new to qt and open for advice. Then the user can press print and it will print five pages...

            thank you

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              Hi,

              What kind of widgets are they ?

              Can you group them in logical units ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              geor 1 Reply Last reply Reply Quote 0
              • geor
                geor @SGaist last edited by

                @SGaist they are a mix of Qcustomplot widgets tables and some text files were a user will fill info such as

                name : (user fills is name)...

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