Qscroll Area eroor



  • 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


  • Moderators

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



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



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


  • Lifetime Qt Champion

    Hi,

    What kind of widgets are they ?

    Can you group them in logical units ?



  • @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)...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.