Nyaruko
Nyaruko

Reputation: 4499

Qt: How to determine whether a widget is visible or not in the QScrollArea?

Someone suggested that I re-implement the QWheelEvent handler and check each child widgets' visibleRegion is 0 or not.

Are there any better suggestions?

Upvotes: 8

Views: 12506

Answers (1)

davepmiller
davepmiller

Reputation: 2708

When you add the widget. Give it a name.

QWidget* myWidget = new QWidget;
myWidget->setObjectName( "myWidget" );
...
//create scroll area
//add a layout to the scroll area
...
scrollArea->layout()->addWidget( myWidget );

Then, check visibility like so:

QWidget* widget = scrollArea->findChild< QWidget* >( "myWidget" );
std::cout << widget->isVisible() << std::endl;

You could keep a list of your widget names to more easily loop through and check when you're ready.

Upvotes: 3

Related Questions