Unsolved Visible region in Qscrollarea
-
@hjohn
Im not sure how u use it.For me it counted the visible lables for me.
With or without scrollbar. with/without scrolling.but they must be visible on screen before u count.
-
@mrjj yeah In My case It does count but It counts 23 instead of 10. It gives right answer when i Scroll.
-
@hjohn
ok. cant guess. works 100% as expected for me. -
@mrjj okay thanks...Have a Good Day :)
-
@hjohn
same to you :)
If you provide a small sample that shows it
count wrong, i will look into it. -
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); area=new QScrollArea(this); area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); for(int i=0;i<23;i++){ button=new QPushButton; button->setText(QString::number(i)); layOut->addWidget(button); } setlabels();
setlabels() function:
P=area->findChildren<QPushButton*>(); for(int i=0;i<P.count() ;i++) { if(!P.at(i)->visibleRegion().isEmpty()) { visibleButtonVectorBottom.push_back(P.at(i)); } }
-
@hjohn
Hi
well, you call it from constructor so widget is not yet visible and
visibleRegion make no sense then.You could use /override
http://doc.qt.io/qt-5/qwidget.html#showEvent
to first call it when shown.Alternatively, you must know size of scroll area and calculate how many is shown using
buttons height. Since its not visible yet, it is not scrolled so should be pretty forward.Can i ask WHY you need to know how many is visible ?
-
@mrjj Actually I want to Display how may widgets in Scrolllarea are not visible at a time.
-
@mrjj Thanks , It worked
I have a further question...QScrollArea *ScrollArea=new QScrollArea; QVBoxLayout *VLayout=new QVBoxLayout; QWidget *widget_in_ScrollAra=new QWidget; widget_in_ScrollAra->setLayout(VLayout); for(int i=0;i<20;i++){ QLabel *Label=new QLabel; Label->setText(QString::number(i)); VLayout->setWidget(Label); } ScrollArea->setWidget(widget_in_ScrollAra);
That's how I'm setting my ScrollArea, But is there a way to add those Label into ScrollArea by making Labels children of widget_in_ScrollAra without using any Layout?
-
@hjohn Sure it is. Just don't create any layout and put the labels manually somewhere in the widget_in_ScrollAra.
Use widget_in_ScrollAra as parent for the labels.