Results 1 to 13 of 13

Thread: A very difficult animation problem...can Qt4 solve it?

  1. #1
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb A very difficult animation problem...can Qt4 solve it?

    Does Qt have a solution for THIS!!!

    Say i have a widget window that displays an image of a butterfly. When

    the user clicks on this butterfly, it dipatches it self from its

    position and moves all over the screen being, sheared/scales/rotated in

    a predefined/random path - could be as simple as just moving along the

    borders of the screen, or diagonally across and back, like a slash '/'

    Thus, the butterfly "leaves" its parent window and moves over other

    windows/desktop etc before settling back in its parent window.

    Is this possible using the very robust Paint Engine of Qt?!?!?!

    Will this solution be platform dependent? If so, I'd prefer to know how

    to achieve the same in Linux/X and windows!!

    Thanks.

    Nupul.

    God bless the one to help me with this...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A very difficult animation problem...can Qt4 solve it?

    Try painting on QApplication::desktop().

  3. #3
    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: A very difficult animation problem...can Qt4 solve it?

    Or animate a widget without background over your desktop. Qt Quarterly issue 16 shows how to achieve widgets with transparent background.

    BTW. Painting on the desktop widget in Qt4 may not be possible (or at least easy) due to the nature of the paint engine present since Qt 4.1.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A very difficult animation problem...can Qt4 solve it?

    Quote Originally Posted by wysota
    BTW. Painting on the desktop widget in Qt4 may not be possible (or at least easy) due to the nature of the paint engine present since Qt 4.1.
    Why should painting on QDesktopWidget be different than painting on QWidget? It just might not work on all systems.

  5. #5
    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: A very difficult animation problem...can Qt4 solve it?

    Qt 4.1 introduces the "backing store" which holds a copy of the widget in memory. It would require to hold a copy of the desktop itself to do it (do window managers allow painting outside windows?). But I think the backing store can be disabled.

    I've been trying to get a transparent widget, but I can't manage to do it. Either my system doesn't support it (which it should) or I simply don't know how to do it.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A very difficult animation problem...can Qt4 solve it?

    Quote Originally Posted by wysota
    I've been trying to get a transparent widget, but I can't manage to do it. Either my system doesn't support it (which it should) or I simply don't know how to do it.
    But it doesn't mean that painting on a particular widget should be harder than on other widgets.

  7. #7
    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: A very difficult animation problem...can Qt4 solve it?

    Well, I seem not to be able to paint on it using such a test program:

    Qt Code:
    1. #include <QApplication>
    2. #include <QDesktopWidget>
    3. #include <QPainter>
    4.  
    5. int main(int argc, char **argv){
    6. QApplication app(argc, argv);
    7. QDesktopWidget *dw = app.desktop();
    8. dw->setAttribute(Qt::WA_PaintOutsidePaintEvent);
    9. QPainter p(dw);
    10. p.drawLine(0,0,dw->width(), dw->height());
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    An alternative would be to catch a paintEvent for it, but I doubt it gets any paint events

    I managed to get a transparent top-level widget using the Qt::WA_PaintOnScreen attribute combined with other attributes but the drawback is that the background under the widget is not refreshed if it changes, so one would have to do that manually (somehow).

  8. #8
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A very difficult animation problem...can Qt4 solve it?

    Quote Originally Posted by wysota
    Well, I seem not to be able to paint on it using such a test program:

    Qt Code:
    1. #include <QApplication>
    2. #include <QDesktopWidget>
    3. #include <QPainter>
    4.  
    5. int main(int argc, char **argv){
    6. QApplication app(argc, argv);
    7. QDesktopWidget *dw = app.desktop();
    8. dw->setAttribute(Qt::WA_PaintOutsidePaintEvent);
    9. QPainter p(dw);
    10. p.drawLine(0,0,dw->width(), dw->height());
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    An alternative would be to catch a paintEvent for it, but I doubt it gets any paint events

    I managed to get a transparent top-level widget using the Qt::WA_PaintOnScreen attribute combined with other attributes but the drawback is that the background under the widget is not refreshed if it changes, so one would have to do that manually (somehow).

    You can always use the old setMask() trick, which may not be as fast/elegant, but it certainly works everywhere!
    Save yourself some pain. Learn C++ before learning Qt.

  9. #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: A very difficult animation problem...can Qt4 solve it?

    Quote Originally Posted by Chicken Blood Machine
    You can always use the old setMask() trick, which may not be as fast/elegant, but it certainly works everywhere!
    The thing is I tried and it didn't work and I don't know why. Does it work in Qt4 with top-level widgets? Could you provide a sample code which does that? I tried something like that and it didn't work:

    Qt Code:
    1. QBitmap bitmap;
    2. bitmap.clear(); // does it set bits to 0 or 1?
    3. setMask(bitmap);
    To copy to clipboard, switch view to plain text mode 

    I could still paint the widget.

  10. #10
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A very difficult animation problem...can Qt4 solve it?

    I can confirm that this works on Suse 10and Windows XP (Qt 4.1.1):
    Qt Code:
    1. sms::PhoneWidget::PhoneWidget(QWidget* parent) :
    2. QWidget(parent, Qt::Window | Qt::FramelessWindowHint)
    3. {
    4. QPixmap pixmap(":/john_phone.png");
    5. resize(pixmap.size());
    6.  
    7. QPalette p(palette());
    8. p.setBrush(QPalette::Window, QBrush(pixmap));
    9. setPalette(p);
    10. setMask(pixmap.mask());
    11. }
    To copy to clipboard, switch view to plain text mode 
    Save yourself some pain. Learn C++ before learning Qt.

  11. #11
    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: A very difficult animation problem...can Qt4 solve it?

    Works for me too, although the pixmap is very aliased. I must have set wrong flags before or in a wrong place.

  12. #12
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A very difficult animation problem...can Qt4 solve it?

    what are the above codes by wysota and CBM are achieving?

    How does it help in answering the query i put forth??

    (not being rude...i am not able to comprehend the fact, that's all

    Thanks

    Nupul

  13. #13
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A very difficult animation problem...can Qt4 solve it?

    Quote Originally Posted by nupul
    what are the above codes by wysota and CBM are achieving?

    How does it help in answering the query i put forth??

    (not being rude...i am not able to comprehend the fact, that's all

    Thanks

    Nupul
    It achieves displaying an irregular (non-square) widget on the desktop - like the butterfy that you described. Why don't you try it and see for yourself?
    Save yourself some pain. Learn C++ before learning Qt.

Similar Threads

  1. How to solve this cc1plus: out of memory problem?
    By triperzonak in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2008, 20:20
  2. Replies: 1
    Last Post: 30th November 2007, 10:03

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.