[Solved] Refresh a QScrollArea()



  • Hi,

    I'm working on a project which needs QScrollArea().

    My problem is that I need to refresh my QScrollArea() but my scrolling widget is in a layout. And this layout in a more global layout.

    I have a violation memory access, the second time I try to update my QScrollArea().

    My guess is that I am doing that refresh wrong ...

    I didn't find any answer in previous posts so if you can help me.

    My code :

       void InitWindowLayout()
       {
    // Layout contenant les indications
    group1 = new QVBoxLayout();
    group1->addWidget(...);
    group1->addWidget(...);
    group2 = new QVBoxLayout();
    group2->addWidget(hand);
    group2->addWidget(....);
    group3 = new QVBoxLayout();
    group3->addWidget(...);
    group3->addWidget(...);
    
    items = new QVBoxLayout();
    items->addSpacerItem(verticalSpacer);
    items->addLayout(group1);
    items->addSpacerItem(verticalSpacer1);
    items->addLayout(group2);
    items->addSpacerItem(verticalSpacer1);
    items->addLayout(group3);
    items->addSpacerItem(verticalSpacer);
    
    group5 = new QHBoxLayout();
    group5->addWidget(...);
    group5->addWidget(...);
    
    scrollArea = new QScrollArea();
    scrollArea->setFixedSize(QSize(640,480));
    
    scrollArea->setStyleSheet("background-color:transparent;");
    scrollArea->setFrameShape(QFrame::NoFrame);
    
    group4 = new QVBoxLayout();
    group4->addLayout(group5);
    group4->setAlignment(group5, Qt::AlignRight);
    group4->addWidget(entrainement);
    group4->addWidget(createLine(255,255,255), NUMBER_OF_COLUMNS_IN_GRID);
    group4->addWidget(scrollArea);
    group4->addSpacerItem(verticalSpacer2);
    
    
    // Layout global avec des marges au-dessus et en-dessous du gridLayout
    globalLayout = new QHBoxLayout();
    globalLayout->addSpacerItem(horizontalSpacer);
    globalLayout->addSpacerItem(verticalSpacer);
    globalLayout->addLayout(items);
    globalLayout->addSpacerItem(horizontalSpacer);
    globalLayout->addLayout(group4);
    globalLayout->addSpacerItem(verticalSpacer);
    globalLayout->addSpacerItem(horizontalSpacer);
    
    // Incorporation du gridLayout dans la fenetre
    setLayout(globalLayout);
      }
    
        void updateScrollArea(){
    
    // Layout contenant les indications
    
    QWidget * dummy = new QWidget();
    dummy->setFixedWidth(620);
    
    QVBoxLayout* data = new QVBoxLayout();
    
    QHBoxLayout*  user = createUserWidget(...);
    
    
    QVBoxLayout*  user_progression = createRecapProgressionWidget(...);
    
    data->addLayout(user );
    data->addSpacerItem(verticalSpacer2);
    data->addLayout(user_progression );
    data->addSpacerItem(verticalSpacer2);
    data->addWidget(createLine(0,0,0), NUMBER_OF_COLUMNS_IN_GRID);
    data->addSpacerItem(verticalSpacer2);
    
    dummy->setLayout(data);
    scrollArea->setWidget(dummy);
    
       }
    

    Have a nice day,

    Racoon


  • Lifetime Qt Champion

    Hi and welcome,

    Can you post a backtrace of when your application crashes ?



  • Problem solved by understanding how to put some widgets in a scroll area.

    Only one widget in a scrollarea and then you can put some other widgets in this widget.

    Don't forget to put the widget resizable to true if you want a display.

    Thanks for your help,

    you can put this thread as solved.

    Racoon


  • Lifetime Qt Champion

    Great !

    You can do that, just update the title prepending [solved] :)


Log in to reply
 

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