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. Qscroll Area eroor

Qscroll Area eroor

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.3k 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.
  • georG Offline
    georG Offline
    geor
    wrote on last edited by
    #1

    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-worxR VRoninV 2 Replies Last reply
    0
    • georG geor

      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-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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
      1
      • georG geor

        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

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @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
        1
        • georG Offline
          georG Offline
          geor
          wrote on last edited by
          #4

          @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
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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

            georG 1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              What kind of widgets are they ?

              Can you group them in logical units ?

              georG Offline
              georG Offline
              geor
              wrote on last edited by
              #6

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

              • Login

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