Can QDockWidget be semi-transparent?
Hi Guys,
I can't seem to make my QDockWidget semi-transparent, and was wondering if it is possible? Here is my code:
Code:
int main(int argc, char *argv[])
{
//The main window just has a label in it's center
QLabel* mainLabel
= new QLabel("Main Widget Label", mainWindow
);
mainWindow->setCentralWidget(mainLabel);
//This dock window should appear 50% transparent. Instead it is fully opaque.
dockWidget->setWidget(pushButton);
dockWidget->setWindowOpacity(0.5);
mainWindow->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
//Just to show transparent can work, this seperate widget does show up 50% transparent.
w->setWindowOpacity(0.5);
//Show the windows.
mainWindow->show();
w->show();
return app.exec();
}
As you can see from the screenshot below, the regular QWidget is semi-transparent but the QDockWidget is not:
http://www.david-williams.info/linke...cy-problem.png
Is this expected? I guess it is conceivable that QDockWidgets are drawn differently (I notice they have different window decorations). Anyone know a way around this, or what I am doing wrong?
Thanks,
David
Re: Can QDockWidget be semi-transparent?
Hi,
it's possible to make an QDockWidget semi-transparent. But in your example the problem is, that after making the QDockWidget floating the opacity is set to 100%. So you have to detected if the widget is maked floating via the signal
Code:
dockLocationChanged ( Qt::DockWidgetArea area )
and set the opacity manually to 50%.
Lykurg
Re: Can QDockWidget be semi-transparent?
Thanks, that did the trick! Shame this doesn't appear to be documented though. Oh, and for anyone else who has this problem the correct signal is actually:
QDockWidget::topLevelChanged(bool)
Re: Can QDockWidget be semi-transparent?
Does this apply to docked QDockWidgets?
Currently on signal "topLevelChanged" I setWindowOpacity(.5) and this doesn't do anything when I "dock" the widget. When it is floating it shows it as having transparency.
Any help would be awesome and thanks for taking time to read this.