Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Count Widgets/Items in ScollArea.



  • I want to count how many items are not in viewport when listed with QScrollarea.
    Here in Image button 0 and button 1 are hide(not in viewport).I want to count widegets/items not in viewport

    0_1533026467259_2.png

    Code :

    #include "widget.h"
    #include "ui_widget.h"
    
    #include<QScrollArea>
    #include<QPushButton>
    #include<QDebug>
    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
      
        QWidget *W=new QWidget(this);
    
        W->setMaximumWidth(700);
        W->setLayout(ui->verticalLayout);
    
        for(int i=0;i<20;i++){
            QPushButton *button=new QPushButton;
    
            ui->verticalLayout->addWidget(button);
            button->setText("buttonOntheLayout"+QString::number(i));
        }
    
        QScrollArea *area=new QScrollArea(this);
        area->resize(140,400);
        area->setWidget(W);
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    


  • Can Anyone Help me!!Its high priority Task for me..



  • It's a user forum, you can't expect answers in real time. Have a look at the docs.
    My first guess would be to use scrollArea->viewport()->visibleRegion(), iterate over all the child widgets and see if their geometry is inside that region



  • @VRonin yeah Thanks..I will look at it..


Log in to reply