Results 1 to 14 of 14

Thread: [QtEmbedded] Translucent QGraphicsView with animated child widgets

  1. #1
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default [QtEmbedded] Translucent QGraphicsView with animated child widgets

    Hi,

    I'm working with Qt 4.6 and I've a QGraphicsView with some animated QGraphicsItems (I'm using QML). I want to make the window background transparent, so I can see the desktop under it.

    I've tried this piece of code:

    Qt Code:
    1. MainWindow::MainWindow(QWidget* parent)
    2. : QmlView(parent)
    3. {
    4. this->setWindowFlags(Qt::FramelessWindowHint);
    5. this->setAttribute(Qt::WA_NoSystemBackground);
    6. this->viewport()->setAutoFillBackground(false);
    7. }
    To copy to clipboard, switch view to plain text mode 

    It works, but only for static widgets: the animated widget paints a trail on the window surface.

    So, how can I erase this trail?
    For example, how does KDE work with desktop semi-transparent animated widgets?
    Last edited by zuck; 5th January 2010 at 14:03.

  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: Translucent QGraphicsView with animated child widgets

    This is not how it works. WA_NoSystemBackground only means the background will not be initialized by the system when the widget is redrawn (hence the garbage left). Use WA_TranslucentBackground instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translucent QGraphicsView with animated child widgets

    I know, but the result is the same in this case (Wa_TranslucentBackground set the WA_NoSystemBackground attribute too).

  4. #4
    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: Translucent QGraphicsView with animated child widgets

    Does this work?

    Qt Code:
    1. #include <QtGui>
    2. #include <QPropertyAnimation>
    3.  
    4. class RectItem : public QObject, public QGraphicsRectItem {
    5. Q_OBJECT
    6. Q_PROPERTY(QPointF pos READ pos WRITE setPos)
    7. public:
    8. RectItem(const QRectF &rect, const QPen &pen, const QBrush &brush) : QObject(), QGraphicsRectItem(rect){
    9. setPen(pen);
    10. setBrush(brush);
    11. }
    12. };
    13.  
    14. #include "main.moc"
    15.  
    16. int main(int argc, char **argv){
    17. QApplication app(argc, argv);
    18. view.setAttribute(Qt::WA_TranslucentBackground);
    19. view.viewport()->setAttribute(Qt::WA_TranslucentBackground);
    20. QGraphicsScene scene(QRectF(0,0,1000,800));
    21. view.setScene(&scene);
    22. RectItem *rect = new RectItem(QRectF(0,0,200,100), QPen(Qt::red), Qt::blue);
    23. scene.addItem(rect);
    24. QPropertyAnimation *anim = new QPropertyAnimation(rect, "pos");
    25. anim->setDuration(10000);
    26. anim->setStartValue(scene.sceneRect().topLeft());
    27. anim->setEndValue(scene.sceneRect().bottomRight());
    28. anim->start();
    29. view.show();
    30. return app.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translucent QGraphicsView with animated child widgets

    No, the behaviour is the same.

    Please, note that I'm working on Qt Embedded for Linux and not on Qt x11.

  6. #6
    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: Translucent QGraphicsView with animated child widgets

    In that case I'd assume your device doesn't allow you to use translucency.

    Please post your problem in the right section of the forum next time.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translucent QGraphicsView with animated child widgets

    I'm sorry.

    Well, currently the test is running on QVFB and not on the final device.

    I've tried to run it with Qt x11 and the result is a window with a black background (the rectangle doesn't paint the trail but the background is fully opaque).

  8. #8
    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: Translucent QGraphicsView with animated child widgets

    Quote Originally Posted by zuck View Post
    I've tried to run it with Qt x11 and the result is a window with a black background (the rectangle doesn't paint the trail but the background is fully opaque).
    It probably means you have composition extension disabled in your X config. Run xdpyinfo and check if Composite is reported as one of the extensions.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translucent QGraphicsView with animated child widgets

    Yes, I have it:

    Qt Code:
    1. number of extensions: 30
    2. BIG-REQUESTS
    3. Composite <----------
    4. DAMAGE
    5. DOUBLE-BUFFER
    6. DPMS
    7. DRI2
    8. GLX
    9. Generic Event Extension
    10. MIT-SCREEN-SAVER
    11. MIT-SHM
    12. NV-CONTROL
    13. NV-GLX
    14. RANDR
    15. RECORD
    16. RENDER
    17. SECURITY
    18. SHAPE
    19. SYNC
    20. X-Resource
    21. XC-MISC
    22. XFIXES
    23. XFree86-DGA
    24. XFree86-VidModeExtension
    25. XINERAMA
    26. XINERAMA
    27. XInputExtension
    28. XKEYBOARD
    29. XTEST
    30. XVideo
    31. XVideo-MotionCompensation
    To copy to clipboard, switch view to plain text mode 

  10. #10
    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: Translucent QGraphicsView with animated child widgets

    The code I gave you works on my system (Linux 2.6 + KDE4 + Qt 4.6). So if it doesn't work on yours, this has to be a hardware or software configuration issue on your end.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translucent QGraphicsView with animated child widgets

    Ok, thanks!

  12. #12
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translucent QGraphicsView with animated child widgets

    It now works on X11 with xcompmgr activated, but it still remains bugged on Qt Embedded

  13. #13
    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: Translucent QGraphicsView with animated child widgets

    Because you have no compositing support there. It simply won't work. You can use QPixmap::grabWidget() to grab the image of the content beneath and render it as background of your widget above.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    zuck (8th January 2010)

  15. #14
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translucent QGraphicsView with animated child widgets

    Yeah! This is the final working code (Qt 4.6):

    Qt Code:
    1. #include <QtGui/QDesktopWidget>
    2. #include <QtGui/QApplication>
    3.  
    4. MainWindow::MainWindow(QWidget* parent)
    5. : QmlView(parent) // or QGraphicsView...
    6. {
    7. this->setWindowFlags(Qt::FramelessWindowHint);
    8. this->setCacheMode(QGraphicsView::CacheBackground);
    9. }
    10.  
    11. void MainWindow::showEvent(QShowEvent* event)
    12. {
    13. WId wid = QApplication::desktop()->winId();
    14.  
    15. int x = this->x();
    16. int y = this->y();
    17. int w = this->width();
    18. int h = this->height();
    19.  
    20. this->setBackgroundBrush(QPixmap::grabWindow(wid, x, y, w, h));
    21.  
    22. QmlView::showEvent(event);
    23. }
    To copy to clipboard, switch view to plain text mode 

    No "WA_TranslucentBackground" or "autoFillBackground(false)" are needed!
    Last edited by zuck; 8th January 2010 at 13:32.

Similar Threads

  1. How to get the child widgets from a Widget?
    By prykHetQuo in forum Qt Programming
    Replies: 2
    Last Post: 29th January 2009, 14:26
  2. Child Widgets In MainWindow
    By RY in forum Newbie
    Replies: 3
    Last Post: 4th October 2008, 09:39
  3. QGraphicsView Handling Child Event
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 01:32
  4. setClipPath on child widgets.
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 27th May 2007, 20:12
  5. initialize child widgets within parent?
    By ucomesdag in forum Newbie
    Replies: 6
    Last Post: 6th June 2006, 09:11

Tags for this Thread

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.