PDA

View Full Version : Styling a Sub-Control based on a Property of the Parent



TheGrimace
10th September 2013, 16:03
I am trying to set the background of a QDockWidget Title bar based on a custom boolean Q_Property I added to a subclass I created.

I know I can do this by calling "setStyleSheet" programmatically, but I was hoping to do it in the style sheet.

Currently this is what I am doing in my style sheet:



QDockWidget#MyDockWidget[myDockWidgetProperty="true"]::title
{
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #AAAAAA, stop: 0.2 #666666, stop: 0.5 #444444, stop: 1.0 #222222);
}

But that does not seem to do it. I have also tried



QDockWidget#MyDockWidget::title[myDockWidgetProperty="true"]
{
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #AAAAAA, stop: 0.2 #666666, stop: 0.5 #444444, stop: 1.0 #222222);
}

But that also failed. In my code I am setting the object name of all my custom dock widgets as "MyDockWidget"


Is there a way to make this work?

Thanks in advance

Added after 31 minutes:

Tried the following also:


QDockWidget#MyDockWidget[myDockWidgetProperty="true"] QDockWidget::title
{
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #AAAAAA, stop: 0.2 #666666, stop: 0.5 #444444, stop: 1.0 #222222);
}

Hoping that the "QDockWidget::title" would think to look only for a child title and not a child QDockWidget, but that does not seem to have worked either.