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. Count Widgets/Items in ScollArea.

Count Widgets/Items in ScollArea.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 720 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.
  • H Offline
    H Offline
    hjohn
    wrote on last edited by hjohn
    #1

    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;
    }
    
    
    1 Reply Last reply
    0
    • H Offline
      H Offline
      hjohn
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        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

        "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

        H 1 Reply Last reply
        6
        • VRoninV VRonin

          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

          H Offline
          H Offline
          hjohn
          wrote on last edited by
          #4

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

          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