PDA

View Full Version : Problem in getting proper visibility state of the widget when using Stylesheet



sraju
1st July 2014, 19:31
Dear Experts,

I am working on an application where in which the MainWidget (Custom class of QWidget) will be the parent widget of all other widgets.

I am creating the child widgets named ChildWidget(Custom class of QWidget) *dynamically* and adding these child widgets into parent's widget's stack in the order which my system impose. (That means stacking order of these child widgets are controlled by my application which is an requirement of my application). Each child widget will have its own visibility state based on the widgets shown on the screen.

Based on some suggestions given by the experts in the below threads (posted by me), my application is working as expected.

http://www.qtcentre.org/threads/56600-show%28%29-on-parent-widget-doesn-t-show-the-child-widgets

http://www.qtcentre.org/threads/56573-Get-the-Window-Visible-State-when-it-is-partially-visible

Earlier I was using QPalette to set the background color of both MainWidget and its child widgets (ChildWidget)


#include <QtGui/QWidget>
#include <QtGui/QPalette>

class MainWidget
{
---
--

private:
QPalette m_palette;
};

class ChildWidget : public QWidget
{
public:
ChildWidget(MainWidget* pParent);
---
---
private:
QPalette m_palette;
};


MainWidget::MainWidget(QWidget* pParent) : QWidget(pParent), m_palette(QPalette())
{
----
m_palette.setColor(QPalette::Background, Qt::white);
setAutoFillBackground(true);
setPalette(m_palette);
}

ChildWidget::ChildWidget(MainWidget* pParent) : MainWidget(pParent), m_palette(QPalette())
{
----
m_palette.setColor(QPalette::Background, Qt::white);
setAutoFillBackground(true);
setPalette(m_palette);
}




Note: With our current system design the visibility state of each child widget (Refer to above link on Visibility state) has the dependency on the background-color set on it.

Now I am planning to create the MainWidget and ChildWidget using Qt Designer and set the background-color for MainWidget using the style sheet.


Open MainWidget.ui ->Right click on the MainWidget->Change Stylesheet -> select the back ground color -> apply & say OK -> save MainWidget.ui

Here are my questions:
a. Is there a way to apply the common style sheet at the parent widget level (for ex MainWidget) so that it applies all its child widgets of type (ChildWidget) without altering their visibility state?
b. How do I know that style sheet data is propagated from parent widget to child widgets?

Thanking You,

Regards
SRaju