Results 1 to 7 of 7

Thread: problem with QPixmap::grabWidget()

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default problem with QPixmap::grabWidget()

    I am trying to implement a sort of a ThumbnailView for arbitrary widgets like QTabWidget. Now, if I try to grab a Pixmap from a widget that has not been shown so far (like a tab), this results in a wierd pixmap being returned by QPixmap::grabWidget(). If the Widget was displayed once, however, the method returns a proper pixmap. This is probably caused by the fact that no paintEvent has been triggered for the Widgets in question but I am not sure.

    Is there a way to work around this? I have included a compilable app highlighting the problem. In thumbnailmode you can doubleclick the items to let them take a new pixmap. Do this for tabs that were displayed and compare with those not displayed yet (i.e. tabs whose associated widget were not shown yet).

    Unfortunately the example code became too large (~270 lines) and too ugly which defeats the purpose of being minimal and thus is not very easy to comprehend. I have attached it to this post nonetheless.

    Thanx in advance

    main.cpp

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

    Default Re: problem with QPixmap::grabWidget()

    i changed grabWidget into m_widget->render(); and i go through all tabwidgets at beginning, to update them.
    Attached Files Attached Files

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

    momesana (18th October 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: problem with QPixmap::grabWidget()

    The trick also works with grabWidget. The decisive parts are the QTimer::singleShot() and activating the current tab before grabbing the widget in the Items constructor. What I do not fully understand is what the QTimer is contributing to this effect and why it does not work without it. I have attached my current version based on your modifications.

    main.cpp

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

    Default Re: problem with QPixmap::grabWidget()

    The timer because i want to wait until the widget is created (with right sizes etc). 1ms is enough for this.
    and i declared createTabWidgets as a slot and a slot cant be called in the constructor. why ever...

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: problem with QPixmap::grabWidget()

    I still wonder why the widget must be activated first. The grabWidget memberfunction documentation says this:

    This function actually asks widget to paint itself (and its children to paint themselves) by calling paintEvent() with painter redirection turned on.
    So, I don't know why on earth the widget must be shown first to get the pixmap right. maybe the paintEvent is not directly executed but rather scheduled to be processed just before the widget is shown. But that also doesn't make sense, since I've tested that with changing widgets (Webkits QWebPage) while in thumbnailmode and the thumbnails correctly reflected the changes (load status) of the QWebPage.

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

    Default Re: problem with QPixmap::grabWidget()

    i think its qtabwidget. if you render or grab any widget which isnt in a tabwidget, it works fine.
    i dont use tabwidget very often because its very buggy (if you apply an scrollarea to a child the child is taken away from tabwidget eg). maybe this is a bug, too.

  8. #7
    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: problem with QPixmap::grabWidget()

    Quote Originally Posted by momesana View Post
    So, I don't know why on earth the widget must be shown first to get the pixmap right. maybe the paintEvent is not directly executed but rather scheduled to be processed just before the widget is shown.
    Geometry of a widget is calculated by the time it's shown for the first time. Until that, geometry is undefined unless one explicitly sets it.

    Quote Originally Posted by kernel_panic View Post
    i dont use tabwidget very often because its very buggy (if you apply an scrollarea to a child the child is taken away from tabwidget eg).
    It would be interesting to see a clear and minimalistic sample code which illustrates this problem.
    J-P Nurmi

Similar Threads

  1. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 08:08
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 10:52
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13:54
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.