Results 1 to 7 of 7

Thread: Transparent Window in qt4.5.1

  1. #1
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Transparent Window in qt4.5.1

    HI all,
    i have a requirement to display a transparent window such that when it is displayed i should be able to see my Desktop.

    I have used setWindowOpacity() for this but it dosen't work.
    Plz give me suggestion to correct my program.
    Below is a small piece of code..................

    Qt Code:
    1. TransparentWindow::TransparentWindow(QWidget *parent)
    2. : QDialog(parent, Qt::FramelessWindowHint)
    3. {
    4.  
    5. QPushButton *bttn = new QPushButton("Test",this);
    6. bttn->setGeometry( QRect( 150, 100,200, 25 ) );
    7. connect(bttn, SIGNAL(clicked()), this, SLOT(setOpaque()));
    8.  
    9. setWindowTitle(tr("Transparent Window"));
    10. //setFixedHeight(sizeHint().height());
    11.  
    12.  
    13. }
    14. void TransparentWindow::paintEvent(QPaintEvent *)
    15. {
    16. QPainter painter(this);
    17. QLinearGradient grad(0, 0, rect().width(), rect().height());
    18.  
    19. painter.fillRect(0, 0, rect().width(), rect().height(), grad);
    20.  
    21. }
    22.  
    23. void TransparentWindow::setOpaque()
    24. {
    25. setAttribute(Qt::WA_NoSystemBackground, true);
    26. setAttribute(Qt::WA_TranslucentBackground, true);
    27. setWindowOpacity(0.1);
    28. repaint();
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 

    Regards

    Raghav

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Transparent Window in qt4.5.1

    just try ..
    use
    void QPainter::setOpacity ( qreal opacity )
    Qt Code:
    1. in paintEvent()
    2. {
    3.  
    4. painter->setOpacity(opacity);
    5. }
    6.  
    7.  
    8. in void TransparentWindow::setOpaque()
    9. {
    10. opacity = 0.2;
    11. update();
    12. }
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Transparent Window in qt4.5.1

    Have a look at Qt::WA_TranslucentBackgroundYou can use it to get a transparent window with non-transparent childs.

  4. #4
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Transparent Window in qt4.5.1

    I have tried the option QPainter::setOpacity ( qreal opacity )
    Still it didn't work.

    Is there any other option.

    Waiting for reply.

    Raghvendra

  5. #5
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transparent Window in qt4.5.1

    setWindowOpacity() works only if you have composite extension enabled in X11. Here's an extract from Qt documentation of setWindowOpacity():

    Note that under X11 you need to have a composite manager running, and the X11 specific _NET_WM_WINDOW_OPACITY atom needs to be supported by the window manager you are using.
    So, in my office PC with composite extension, setWindowOpacity() doesn't work but it works on my laptop as i have composite extension (Beryl 3D) installed.

  6. #6
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Transparent Window in qt4.5.1

    Thnx for that Information.

    Could you plz tell me how can i enable composite extension in X11. I am new to this concept.

    Plz do reply...............

    Regards
    raghvendra

  7. #7
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transparent Window in qt4.5.1

    oops, sorry i missed this thread for long
    u can just google for "how to enable composite extension in linux or X11"

    Also, if you just want to show your desktop and make your window appear as transparent, you can use the grabWindow function to get the desktop background as a QPixmap and then you can just set your window background to that pixmap.

Similar Threads

  1. How to set Qt window transparent?
    By montylee in forum Qt Programming
    Replies: 17
    Last Post: 24th December 2013, 21:11
  2. how QTextEdit transparent to his parent window?
    By wesley in forum Qt Programming
    Replies: 4
    Last Post: 16th September 2009, 08:23
  3. Transparent window with QGLWidget
    By ultr in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2008, 08:01
  4. Regarding drawing on Transparent Window
    By Shalabh in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2007, 11:32
  5. Making some part of window transparent
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2006, 21:36

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.