Improper Visibility State of the ChildWidget when Style Sheet is used to set the background color
-
Dear Experts,
I am working on an application with the following requirements and features:
a. A custom QWidget named "MainWidget" which is a Parent Widget.
b. A set of custom QWidgets of type named "ChildWidget" with the parent as MainWidget.
c. Each ChildWidget has its own unique size (height and width)
c. ChildWidgets are inserted into OR removed from the MainWidget's stack of widgets in the Qt Event loop on the fly ( i.e., Dynamically add & remove)
d. The stacking order of all ChildWidgets in the MainWidget Widget's stack is controlled by application with the help of "QWidget::stackUnder()" function (It's an special requirement of the application)
e. Once after inserting the ChildWidget to the MainWidget's Stack of widgets, the "show()" of Childwidget is called to make sure that visible state of the ChildWidget is set to true so that when MainWidget's show() event is processed, it should display the newly added ChildWidget as well.
f. The visible state of each ChildWidget will be calculated when any ChildWidget is removed from the Stack of MainWidget.
g. The visible states of each child widget is determined based on the visibility region and number of visible region rectangles as follows:
@
void printChildVisibilityState(QWidget pMainWidget)
{
// Find Direct child of pParentWidget and for each direct child widget
QList<ChildWidgett> childWidgetsList =
findDirectChildObjects<ChildWidget*>(pMainWidget);for (register int i = 0; i < childWidgetsList.size(); i++) { ChildWidget* pWidget = childWidgetsList.at(i); QRegion visibleRegion = pWidget->visibleRegion(); QRect visibleRegionBoundingRect = visibleRegion.boundingRect(); int visibleRegionRectsCount = visibleRegion.rects().count(); QRect widgetRect = pWidget->rect(); if (visibleRegion.isEmpty()) { qDebug() << "is OBSCURED"; } else { if ( (visibleRegionBoundingRect == widgetRect) && (1 == visibleRegionRectsCount) ) { qDebug() << "is VISIBLE"; } else { qDebug() << "is PARTIALLY VISIBLE"; } } } } @
I am getting proper visibility state of each child widget only when I set the autoFillBackground property of child widget to true during its construction.
@ pChildWidget->setAutoFillBackground(true); @
OR
@ Set the autoFillBackground property to true in MainWidget.ui & ChildWidget.ui @
However, I am planning to use the style sheet for both MainWidget and all its ChildWidgets with the idea that, apply common style sheet data at the MainWidget so that it propagates to ChildWidget.
For example Set the background color of both MainWidget using style sheet as follows:
@
Open the MainWidget.ui in Qt Creator
Right Click on MainWidget
Select Change Stylesheet
Add Background color
Save the MainWidget
@When I try to use the style sheet for the MainWidget & ChildWidget (using Qt creator ) the autoFillBackground property will be reset to false due to which the visibility state of all ChildWidgets will be shown always as VISIBLE ( i.e.., Number of visible rectangles always set to 1) even when one ChildWidget is overlapped by other or one ChildWidget is obscured by other childWidget.
Note: I have also tried setting the background-color of all the QWidgets application wide as shown below.
@
myGuiApp->setStyleSheet("QWidget { background-color: white }");
@But there was no success in getting proper visibility state of each child widgets.
Why would the difference in visibility state of each child widget when used Style Sheets?
Is there a equivalent for achieving autoFillBackground(true) in style sheets?
Am I missing anything in finding the visibility state of ChildWidget?References:
"SolutionForVisibilityState1":http://www.qtcentre.org/threads/56600-show()-on-parent-widget-doesn-t-show-the-child-widgets
"SolutionForVisibilityState2":http://www.qtcentre.org/threads/56573-Get-the-Window-Visible-State-when-it-is-partially-visiblePlease suggest.
Thanking You,
Regards
SRaju