Results 1 to 4 of 4

Thread: Can QDockWidget be semi-transparent?

  1. #1
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. //The main window just has a label in it's center
    6. QMainWindow* mainWindow = new QMainWindow(0,0);
    7. QLabel* mainLabel = new QLabel("Main Widget Label", mainWindow);
    8. mainWindow->setCentralWidget(mainLabel);
    9.  
    10. //This dock window should appear 50% transparent. Instead it is fully opaque.
    11. QDockWidget* dockWidget = new QDockWidget("Dock Widget", mainWindow);
    12. QPushButton* pushButton = new QPushButton("Dock Widget Button", dockWidget);
    13. dockWidget->setWidget(pushButton);
    14. dockWidget->setWindowOpacity(0.5);
    15. mainWindow->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
    16.  
    17. //Just to show transparent can work, this seperate widget does show up 50% transparent.
    18. QWidget *w = new QWidget(0,0);
    19. QPushButton* floatingPushButton = new QPushButton("Floating Widget Button", w);
    20. w->setWindowOpacity(0.5);
    21.  
    22. //Show the windows.
    23. mainWindow->show();
    24. w->show();
    25.  
    26. return app.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    As you can see from the screenshot below, the regular QWidget is semi-transparent but the QDockWidget is not:



    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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
    Qt Code:
    1. dockLocationChanged ( Qt::DockWidgetArea area )
    To copy to clipboard, switch view to plain text mode 
    and set the opacity manually to 50%.


    Lykurg

  3. #3
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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)

  4. #4
    Join Date
    Oct 2008
    Location
    Murfreesboro, TN
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

Similar Threads

  1. Semi transparent QDialog
    By cs_raja in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 10:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.