Page 1 of 2 12 LastLast
Results 1 to 20 of 33

Thread: Display only PNG image on desktop

  1. #1
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Display only PNG image on desktop

    Hello,

    Well, you probably all already heard this question 100x times before and I just finished 3 hours of research for this problem.

    All I need right now is a confirmation that I simply cannot display PNG images ontop of my desktop with Qt4/Windows.
    I don't mean like display them in a window, I just mean the PNG image with no dialog or window/backgound whatsoever.

    I know I can display a simple png image on my desktop (assuming the image is rectangular with no transparent pixels),
    and I know I can display some an image with completely transparent pixels using setMask(),
    and I know I can display the whole image transparent (setWindowOpacity())...

    ...but what I can't seem to be able to do (under Windows!) is to display an image which has some opaque and some 20% transparent pixels and some 50% transparent pixels and so on.

    So assuming I have this image (as you can see the shadow around the egg is transparent):



    And I want it do be display on my desktop:



    So I've seen all kinds of solutions with setMask() and whatever but all I need is a confirmation that under Windows I simply cannot use Qt to achieve this effect.

    So can anyone confirm that this is not possible with Qt (yet) so that I can stop searching for a solution?
    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only PNG image on desktop

    I'm sorry but I can't confirm that. I think it should be possible to achieve Try setting the Qt::WA_NoSystemBackground attribute for your frameless window.

  3. #3
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    Yeah, I already tried that and stuff like Qt::WA_OpaquePaintEvent and Qt::WA_PaintOnScreen and yes, it gives a transparent window background, but as soon as I try to paint on it or just put a QLabel in it, the background is black with my QLabel ontop

    Maybe this is supposed to work on Windows but no one at TT noticed yet that it doesn't work very well on Windows Vista?

    I actually also thought that this would be a simple thing to achieve and I was pretty surprised that it wasn't that easy after all.

    I also looked into that:
    http://labs.trolltech.com/page/Graph...ples/Examples1 (first example - "ARGB")
    And according to its source code even TT needed to use X11 calls (which I obviously don't have on Windows :P) to display that bird.
    I downloaded it and removed the X11 calls from the int main() function - the bird has a gray and black background in its window (gray with no attributes and black with the aforementioned attributes).

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only PNG image on desktop

    Native X11 calls are needed on X11, because by default the visuals returned by X11 don't have the alpha component and you have to ask for it specifically. This shouldn't be the issue on Windows.

    Of course you can always "emulate" the correct behaviour with setMask(), moveEvent(), QImage, QDesktopWidget and QWidget::grabWindow(). But I still think it should be possible to do it on Windows without special tricks provided that your screen is 32bits deep and supports compositions.

  5. #5
    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: Display only PNG image on desktop

    Yes you can.
    First fill your widget with a transparent pixmap ( filled with Qt::transparent ), and then draw your argb png.

    Tested ()

    Regards

  6. #6
    Join Date
    May 2007
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    Can you show example?
    I can't understand how i can fill the widget with Qt::transperent.

  7. #7
    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: Display only PNG image on desktop

    In the widget's paint event.
    Something like this:

    Qt Code:
    1. void MyWidget::paintEvent( QPaintEvent* )
    2. {
    3. QPainter painter( this );
    4. QPixmap pix( size() );
    5. pix.fill( Qt::transparent );
    6. painter.drawPixmap( 0, 0, pix );
    7. //Now the widget is completely transparent
    8. //You can draw now your png
    9. }
    To copy to clipboard, switch view to plain text mode 
    Also, once you make sure the code works, you might want to optimize it a bit by creating the transparent pixmap only once.

    regards

  8. #8
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    Did you really try that? Because I already did try it and just tried it again but it won't work.

    With no special attributes I still have the usual gray Windows background and with the Qt::WA_OpaquePaintEvent / Qt::WA_NoSystemBackground attribute I get a black background as soon as I start painting anything on the widget.

    I'm starting to think that this is a regression from Qt on Windows Vista.
    Marcel, did you try it on Windows Vista or XP and what additional attributes did you use?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only PNG image on desktop

    Maybe your desktop doesn't support compositions?

  10. #10
    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: Display only PNG image on desktop

    No, only on XP.

  11. #11
    Join Date
    May 2007
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    Me too, black background.

  12. #12
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    Pakulo, do you also use Vista?

    Wysota, I don't know but I think my system is pretty much up to date

    So it seems that this is a regression of Qt on Vista. You guys think I should submit this to TT's bug tracker as a suggestion/bug?

  13. #13
    Join Date
    May 2007
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    I am use Window XP

  14. #14
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    Are you sure you did the right thing, pakulo? Because Marcel says it works for him on Windows XP.
    Please show us some code (paintEvent and maybe hwo your constructor looks like with the appropriate attribute calls).

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only PNG image on desktop

    Quote Originally Posted by durbrak View Post
    Wysota, I don't know but I think my system is pretty much up to date
    That doesn't mean anything. The particular feature may be disabled on unsupported on your version/installation of the system.

    So it seems that this is a regression of Qt on Vista. You guys think I should submit this to TT's bug tracker as a suggestion/bug?
    You can, but I'd first verify this is not caused by your installation. I don't think there should be any regression in this matter.

  16. #16
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    Yeah well, I didn't turn any features in my OS off or something like that (at least not that I'm aware of). Besides, I have dozens of applications who can do this on my rig (Windows Sidebar, Trillian Astra, CD Art Display, ...)

    It just seems weird that on Pakulo's WinXP it doesn't seem to work either even though it does work for Marcel...

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only PNG image on desktop

    Quote Originally Posted by durbrak View Post
    It just seems weird that on Pakulo's WinXP it doesn't seem to work either even though it does work for Marcel...
    Which also suggests it's a configuration issue. Maybe his video card supports 32b visuals and yours doesn't. I guess that the same effect may be obtained in different ways, so I'm not convinced by an argument that other applications are able to achieve an effect that looks the same. Have you seen their sources?

  18. #18
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display only PNG image on desktop

    Well, still the other applications achieve somehow this affect...

    Anyway, the funny thing is: I was just about to go to the TT Task Tracker to submit this as a suggestion and guess what? I looked through the newest submissions and someone already suggested this 2.5 hours ago

    http://www.trolltech.com/developer/t...ntry&id=162697

    I wonder who that was

  19. #19
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display only PNG image on desktop

    search google for "UpdateLayeredWindow". Then you'll find many solutions. just port it to qt and everything is ok.

  20. #20
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Display only PNG image on desktop

    Is there any solution for mac?

Similar Threads

  1. Display and divide the image
    By kiransu123 in forum Qt Programming
    Replies: 19
    Last Post: 5th March 2007, 20:40
  2. How to Read and display BMP image using QT
    By agsrinivasan in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 07:14
  3. Simple display of an image
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 15th January 2007, 23:49
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. How to display a QByteArray as an Image ?
    By probine in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 13:45

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.