Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 757
Nyaruko Avatar asked Feb 24 '15 15:02

Nyaruko


People also ask

How do I hide widgets in Qt?

You can set your push button checkable an d connect clicked(bool) with setVisible(bool) of your widget. @abhay To add to @Roy44 's answer you can just connect button's clicked signal to hide and show slots.

What are qt5 widgets?

Widgets are the primary elements for creating user interfaces in Qt. Widgets can display data and status information, receive user input, and provide a container for other widgets that should be grouped together. A widget that is not embedded in a parent widget is called a window.

How do you hide the spacer in Qt?

Try putting the button you want to hide and unhide in another layout. In that layout along with the button put a spacer. Call Button hide and spacer will take over. Spacer takes over hidden button's space.


1 Answers

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.

like image 114
davepmiller Avatar answered Oct 03 '22 13:10

davepmiller