Results 1 to 11 of 11

Thread: semi-transparent window with a visible line on it

  1. #1
    Join Date
    Apr 2007
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default semi-transparent window with a visible line on it

    Hi to all and good to be here!

    I'm using Qt 4.2.3 on Windows XP and i'm trying to do a semi-transparent principal window drawing a simple line on it, changing the paintEvent of the Qwidget.
    I don't want that line to be transparent. I used setWindowOpacity(0.0) but the line on it becames also tranparent.
    How can i achieve my goal?

    Any help would be appreciated.
    Thanks,

    nagpalma

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: semi-transparent window with a visible line on it

    In paintEvent(). where you draw the line, use painter->setOpacity( 1.0f ) before you draw the line and after you draw the line restore the original opacity.

    Regards

  3. #3
    Join Date
    Apr 2007
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: semi-transparent window with a visible line on it

    Hi marcel,

    it didn't solve the problem
    I'm using the fowlling code:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "transparent.h"
    4.  
    5. Transparent::Transparent(QWidget *parent)
    6. : QWidget(parent, Qt::FramelessWindowHint)
    7. {
    8. setWindowTitle(tr("Transparent Window"));
    9. setWindowOpacity(0.0);
    10. }
    11.  
    12.  
    13. //window.resize(400, 400);
    14.  
    15. //window.setFixedSize(500,500);
    16. //window.showMaximized();
    17.  
    18.  
    19. void Transparent::paintEvent(QPaintEvent *)
    20. {
    21. QPainter p(this);
    22. p.setOpacity(1.0);
    23. p.drawLine(0, 0, 50, 50); // drawing code
    24. p.setOpacity(0.0);
    25. }
    26.  
    27. QSize Transparent::sizeHint() const
    28. {
    29. return QSize(400, 400);
    30. }
    To copy to clipboard, switch view to plain text mode 

    When i execute the application, the line doesn't appear
    Last edited by wysota; 27th April 2007 at 11:03. Reason: missing [code] tags

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: semi-transparent window with a visible line on it

    Quote Originally Posted by nagpalma View Post
    setWindowOpacity(0.0);
    Just curious, what if you try:
    Qt Code:
    1. setWindowOpacity(0.01);
    To copy to clipboard, switch view to plain text mode 

    I once tried to catch (drag and drop) events with a window having opacity of 0.0. No events were received until I changed the opacity to something non-zero. I think a window with opacity of 0.0 basically means a hidden window and it won't even receive paint events then.

    Edit: Oh, and please use "[ code ]"-tags to make code snippets more readable.
    J-P Nurmi

  5. #5
    Join Date
    Apr 2007
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: semi-transparent window with a visible line on it

    thanks for your reply jpn, i changed to setWindowOpacity(0.01) but i got the same result

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: semi-transparent window with a visible line on it

    I have my doubts that one could really turn QPainter opaque on a window that has been made transparent at system level. I'm not in Windows right now so I can't test (and neither do I have an extension manager running on X11). But what about testing for example with setWindowOpacity(0.5) if QPainter::setOpacity() really has any effect then?
    J-P Nurmi

  7. #7
    Join Date
    Apr 2007
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: semi-transparent window with a visible line on it

    I tried setWindowOpacity(0.5) and i don't think QPainter::setOpacity() has any effect at all

  8. #8
    Join Date
    Apr 2007
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: semi-transparent window with a visible line on it

    Hi,

    I confirm, QPainter::setOpacity() had no effect after use setWindowOpacity().
    Any suggestions?

    Thanks,
    nagpalma

  9. #9
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: semi-transparent window with a visible line on it

    Quote Originally Posted by nagpalma View Post
    Hi,

    I confirm, QPainter::setOpacity() had no effect after use setWindowOpacity().
    Any suggestions?

    Thanks,
    nagpalma
    This code works for me on windows Xp
    Qt Code:
    1. Transparent::Transparent(QWidget *parent)
    2. : QWidget(parent) {
    3. setWindowTitle(tr("Transparent Window"));
    4. setWindowOpacity(0.2f);
    5. }
    6. void Transparent::paintEvent(QPaintEvent *) {
    7. QPainter p(this);
    8. p.setPen( QPen( Qt::red ) );
    9. p.setOpacity(1.0f);
    10. p.drawLine(0, 0, 50, 50);
    11. p.setOpacity(0.0f);
    12. }
    13. int main(int argc, char *argv[]){
    14. QApplication a(argc, argv);
    15. Transparent w;
    16. w.show();
    17. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    18. return a.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: semi-transparent window with a visible line on it

    Quote Originally Posted by vermarajeev View Post
    This code works for me on windows Xp
    Make it
    Qt Code:
    1. p.setPen( QPen( Qt::red, 5 ) );
    To copy to clipboard, switch view to plain text mode 
    and you'll notice that the line is transparent too.
    J-P Nurmi

  11. #11
    Join Date
    Apr 2007
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: semi-transparent window with a visible line on it

    I tried your code Vermarajeev but like jpn said, the line remains transparent

    nagpalma

Similar Threads

  1. Transparent window with QGLWidget
    By ultr in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2008, 07:01
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  4. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  5. Making some part of window transparent
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2006, 20: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.