Results 1 to 19 of 19

Thread: ARGB windows on Windows?

  1. #1
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default ARGB windows on Windows?

    It's a pity that
    QApplication::QApplication ( Display * display, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0 )
    is X11 only. I wonder if there is any way on Windows and OS X to create a window which can be drawn to using transparent brush and will in turn be transparent (like with the above constructor for X11 as shown here: svn://labs.trolltech.com/svn/graphics/dojo/argb).

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

    Default Re: ARGB windows on Windows?

    It should work fine without any special tricks on systems that support that (Windows 2000+ and appropriate graphics card driver that supports ARGB visuals).

  3. #3
    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: ARGB windows on Windows?

    Quote Originally Posted by wysota View Post
    It should work fine without any special tricks on systems that support that (Windows 2000+ and appropriate graphics card driver that supports ARGB visuals).
    There have been a few attempts to display transparent pngs on top level widgets, even here on QtCentre.
    As far as I know, it won't work on XP and 2000. Only on Mac and X11(with the composite extension enabled), and on Vista with the help of platform API(that might have been changed since Qt 4.3 ).

    Regards

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

    Smile Re: ARGB windows on Windows?

    it's possible on windows xp and 2000 too. The problem is that you can't use control elements anymore.
    you just have to set your windowLong to EX_LAYERED and call UpdateLayeredWindow with an image you want to display semi-transparent on the desktop.
    search google for UpdateLayeredWindow. There are many examples.

    I ask me, how the Yahoo Widget Engine does the ARGB-Widgets.... They can use control-elements and it runs on windows xp/2000....

  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: ARGB windows on Windows?

    Quote Originally Posted by kernel_panic View Post
    it's possible on windows xp and 2000 too. The problem is that you can't use control elements anymore.
    you just have to set your windowLong to EX_LAYERED and call UpdateLayeredWindow with an image you want to display semi-transparent on the desktop.
    search google for UpdateLayeredWindow. There are many examples.

    I ask me, how the Yahoo Widget Engine does the ARGB-Widgets.... They can use control-elements and it runs on windows xp/2000....
    I think the original post talked about the ARGB windows example at trolltech labs.
    That is more than a simple image layered on a window.

    That you can't do on XP.

    Take a look.

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

    Default Re: ARGB windows on Windows?

    I know that the trolltech example doesn't work...
    Therefore i postet how sth like this works on windows.
    But ARGB window is ARGB window, if you do this with the solution of trolltech or with UpdateLayeredWindow, or?
    please read the first pos again:
    I wonder if there is any way on Windows
    He ask for ANY WAY!!!!!!!
    Last edited by kernel_panic; 9th August 2007 at 13:34.

  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: ARGB windows on Windows?

    OK, ok, it can be done, but it is not easy.
    Take a look at what this guy did: http://www.codeproject.com/useritems...kingDialog.asp.

    It offers real time backdrop composition, although it keeps the processor at 100%.

    ask me, how the Yahoo Widget Engine does the ARGB-Widgets.... They can use control-elements and it runs on windows xp/2000....
    They probably built an entire framework on top of the Windows composition/translucency API.
    Anyway, in the example above, there are a few non-transparent controls.
    They did by using an opaque area as background for the controls.
    From what I have seen in the code even the control are stored in a backbuffer and painted on the image passed to UpdateLayeredWindow.

    Regards

  8. The following user says thank you to marcel for this useful post:

    kernel_panic (10th August 2007)

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

    Default Re: ARGB windows on Windows?

    hey! sry for flaming.... had a bad day....
    but this example is great. i'll try to port this to qt and build some classes, mkay?
    is it possible to draw qt-controls into a pixmap instead on the widget? this would help much.

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

    Default Re: ARGB windows on Windows?

    Yes, it's possible. You can redirect a paint event into another paint device, but it's quite tedious not to lose control.

  11. The following user says thank you to wysota for this useful post:

    kernel_panic (10th August 2007)

  12. #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: ARGB windows on Windows?

    Quote Originally Posted by wysota View Post
    Yes, it's possible. You can redirect a paint event into another paint device, but it's quite tedious not to lose control.
    You always have QPixmap::grabWidget().

    It also grabs the children so if you have a container widget you can make things easy and grab all the widgets you want in one step.

    EDIT: ok, forget that . QPainter::setRedirected is better.
    QPixmap::grabWidget requires the widget to be visible.

    Regards
    Last edited by marcel; 10th August 2007 at 14:13.

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

    Default Re: ARGB windows on Windows?

    i call this in my paintEvent, but nothing is paintet in the pixmap, why?
    Qt Code:
    1. QObjectList ol = children();
    2. foreach(QObject *o, ol)
    3. {
    4. if(o->isWidgetType())
    5. {
    6.  
    7. QWidget* child = qobject_cast<QWidget*>(o);
    8.  
    9.  
    10. QPainter::setRedirected(child->paintEngine()->paintDevice(), &widgetMask);
    11.  
    12.  
    13. }
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    and than i update the pixmap onto my layered Window

    Qt Code:
    1. HBITMAP oldBitmap;
    2. HBITMAP hBitmap;
    3. SIZE size;
    4. size.cx = widgetMask.width();
    5. size.cy = widgetMask.height();
    6. HDC screenDc = GetDC(NULL);
    7. POINT pointSource;
    8. pointSource.x = 0;
    9. pointSource.y = 0;
    10. POINT topPos;
    11. topPos.x = x();
    12. topPos.y = y();
    13. HDC memDc = CreateCompatibleDC(screenDc);
    14. BLENDFUNCTION blend;
    15. blend.BlendOp = AC_SRC_OVER;
    16. blend.BlendFlags = 0;
    17. blend.SourceConstantAlpha = alpha;
    18. blend.AlphaFormat = AC_SRC_ALPHA;
    19. hBitmap = widgetMask.toWinHBITMAP(QPixmap::PremultipliedAlpha); // grab a GDI handle from this GDI+ bitmap
    20. oldBitmap = (HBITMAP)SelectObject(memDc, hBitmap);
    21.  
    22. UpdateLayeredWindow(winId(), screenDc, &topPos, &size, memDc, &pointSource, 0, &blend, ULW_ALPHA);
    23.  
    24. //
    25. ReleaseDC( NULL, screenDc);
    26. if (hBitmap != NULL)
    27. {
    28. SelectObject(memDc, oldBitmap);
    29. //DeleteObject(hBitmap); // The documentation says that we have to use the Windows.DeleteObject... but since there is no such method I use the normal DeleteObject from Win32 GDI and it's working fine without any resource leak.
    30. DeleteObject(hBitmap);
    31. }
    32. DeleteDC(memDc);
    To copy to clipboard, switch view to plain text mode 
    Last edited by kernel_panic; 10th August 2007 at 16:22.

  14. #12
    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: ARGB windows on Windows?

    QPainter::setRedirected is not meant to be used inside a paintEvent.
    You just do it once, for every widget, somewhere else, and just use the pixmap.

    However, a better solution is this:
    Qt Code:
    1. QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect)
    2. {
    3. if (!widget)
    4. return QPixmap();
    5.  
    6. if (widget->testAttribute(Qt::WA_PendingResizeEvent) || !widget->testAttribute(Qt::WA_WState_Created))
    7. sendResizeEvents(widget);
    8.  
    9. QRect r(rect);
    10. if (r.width() < 0)
    11. r.setWidth(widget->width() - rect.x());
    12. if (r.height() < 0)
    13. r.setHeight(widget->height() - rect.y());
    14.  
    15. if (!r.intersects(widget->rect()))
    16. return QPixmap();
    17.  
    18. QPixmap res(r.size());
    19. widget->render(&res, -r.topLeft(), r,
    20. QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask);
    21. return res;
    22. }
    To copy to clipboard, switch view to plain text mode 
    As you can see, this is the grabWidget function from QPixmap.
    I think it is better to just call QWidget::render. In fact, I think you can use most of the code in this function.

    QPainter::setRedirected is too hard to use.

    But I wonder, if you use a pixmap top show the actual widgets, how do you handle widget interaction? For example when a button is pressed... Do you plan to update the pixmap?

    EDIT: if you use QPainter::setRedirected you have to send paint events to the widget(s) in question to make them paint themselves.

    EDIT2: I guess you'll have to try many solutions and many methods until you find something that works well. I never tried something like this, so at most I can give you some suggestions which are not guaranteed to work( but the logical conclusion is that they do ).
    Anyway, it would be nice to show us a demo after you finish it.

    Regards
    Last edited by marcel; 10th August 2007 at 16:30.

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

    Default Re: ARGB windows on Windows?

    button presses and everything else works fine. you just don't see the controls.
    and for resizing and moving i've the solution from my skin-classes.

  16. #14
    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: ARGB windows on Windows?

    Here's a sample on how to call setRedirected(still from the Qt sources):
    Qt Code:
    1. // Redirect all paint commands from the widget to the paint device and
    2. // tell the widget to repaint itself.
    3. QPainter::setRedirected(widget, result, rect.topLeft() - offset);
    4. QPaintEvent paintEvent(rect & widget->rect());
    5. QApplication::sendEvent(widget, &paintEvent);
    6. QPainter::restoreRedirected(widget); // you won't need this however
    To copy to clipboard, switch view to plain text mode 


    Regards

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

    Default Re: ARGB windows on Windows?

    i've done it!!!!!!!!!!
    IT WORKS!

    and less work than the example on codeproject.
    Attached Files Attached Files

  18. The following user says thank you to kernel_panic for this useful post:

    marcel (10th August 2007)

  19. #16
    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: ARGB windows on Windows?

    I think I better build the example since your exe is linked agains mingwm10.dll, and I don't have mingw.

    Regards

  20. #17
    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: ARGB windows on Windows?

    OK. Really nice!!
    And it doesn't kill the processor either, like the original example.

    EDIT:
    Qt Code:
    1. setWindowFlags(Qt::FramelessWindowHint | Qt::Widget);
    To copy to clipboard, switch view to plain text mode 
    I used this instead of subwindow, since I cannot spot it in the task bar.

    Regards

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

    Default Re: ARGB windows on Windows?

    i hope this will make the windows-qt world much better.
    grins

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

    Lightbulb Re: ARGB windows on Windows?

    i've setup my skin-classes with the argb support. look into the Software section.

Similar Threads

  1. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00
  2. Qt and windows vista
    By munna in forum General Discussion
    Replies: 8
    Last Post: 11th January 2006, 22:33

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.