PolyVox
29th September 2008, 22:24
Hi Guys,
I can't seem to make my QDockWidget semi-transparent, and was wondering if it is possible? Here is my code:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//The main window just has a label in it's center
QMainWindow* mainWindow = new QMainWindow(0,0);
QLabel* mainLabel = new QLabel("Main Widget Label", mainWindow);
mainWindow->setCentralWidget(mainLabel);
//This dock window should appear 50% transparent. Instead it is fully opaque.
QDockWidget* dockWidget = new QDockWidget("Dock Widget", mainWindow);
QPushButton* pushButton = new QPushButton("Dock Widget Button", dockWidget);
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.
QWidget *w = new QWidget(0,0);
QPushButton* floatingPushButton = new QPushButton("Floating Widget Button", w);
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/linked_from_web/qt/transparency-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
I can't seem to make my QDockWidget semi-transparent, and was wondering if it is possible? Here is my code:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//The main window just has a label in it's center
QMainWindow* mainWindow = new QMainWindow(0,0);
QLabel* mainLabel = new QLabel("Main Widget Label", mainWindow);
mainWindow->setCentralWidget(mainLabel);
//This dock window should appear 50% transparent. Instead it is fully opaque.
QDockWidget* dockWidget = new QDockWidget("Dock Widget", mainWindow);
QPushButton* pushButton = new QPushButton("Dock Widget Button", dockWidget);
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.
QWidget *w = new QWidget(0,0);
QPushButton* floatingPushButton = new QPushButton("Floating Widget Button", w);
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/linked_from_web/qt/transparency-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