Results 1 to 6 of 6

Thread: QPainter::begin: Cannot paint on a null pixmap

  1. #1
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face QPainter::begin: Cannot paint on a null pixmap

    Hi,
    I have a QTreeWidget in my application. I load some values and icons into that tree. My code is here,

    item = new QTreeWidgetItem(ManagerTree);
    item->setExpanded( true );
    item->setText( 0, "country" );
    item->setIcon(0,QIcon("D:\Images\image.png"));

    and it is working. But When i set the property
    ManagerTree->setAnimated(true);
    and make, then I didn't get any warning or errors. But when I run the program, it display some messages like this in my cunsol.

    QPainter::begin: Cannot paint on a null pixmap
    QPainter::setWorldTransform: Painter not active
    QPainter::end: Painter not active, aborted

    How can I solve it?
    Please help me..............

  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: QPainter::begin: Cannot paint on a null pixmap

    Which Qt release do you use?

  3. #3
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter::begin: Cannot paint on a null pixmap

    Hello,

    I have the same problem. I have a form with an embedded QTreeWidget. I fill the tree widget with items in the form's constructor. As soon as I set the "animated" property of the QTreeWidget to true, I get the following run-time warnings:

    Qt Code:
    1. QPainter::begin: Cannot paint on a null pixmap
    2. QPainter::translate: Painter not active
    3. QPainter::end: Painter not active, aborted
    To copy to clipboard, switch view to plain text mode 

    After adding the items to QTreeWidget, I expand the top-level tree items to reveal the items they contain. If I comment out the statement expanding the items (widgetItem->setExpanded()), the warning disappears.

    I'm using Qt 4.5.1 on a RedHat system.

    Thanks in advance for any suggestions!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPainter::begin: Cannot paint on a null pixmap

    well a possibly solution could be to set the animated option at the end of your c-tor, after you have expanded your items. The user will see nothing either because the widget is shown after the c-tor is finished.

  5. The following user says thank you to Lykurg for this useful post:

    BadHare (17th June 2009)

  6. #5
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter::begin: Cannot paint on a null pixmap

    Lykurg,

    Thanks, this works well enough. So, in the form designer I cleared the animated property of my QTreeWidget. In the form's constructor I add items to the tree, expanding header items appropriately, and once I'm done, I set the animated property to true.

    It would be interesting to find out what the problem was to begin with (animation while the widget is not displayed, perhaps?).

    Thanks again!

  7. #6
    Join Date
    Jul 2010
    Location
    Toronto
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPainter::begin: Cannot paint on a null pixmap

    Quote Originally Posted by BadHare View Post
    Lykurg,

    Thanks, this works well enough. So, in the form designer I cleared the animated property of my QTreeWidget. In the form's constructor I add items to the tree, expanding header items appropriately, and once I'm done, I set the animated property to true.

    It would be interesting to find out what the problem was to begin with (animation while the widget is not displayed, perhaps?).

    Thanks again!
    It seems that QTreeWidget doesn't like directly altering QTreeWidgetItem's "expanded" status via QTreeWidgetItem itself when Animation is enabled.

    I had to turn off the animation before doing QTreeWidgetItem::setExpanded () and then turn the animation back on after.. It worked like a charm!
    (It resolves the warning issue, and still lets the user see the pleasant animation when she interacts with the TreeWidget)

    The problem in my case was a little bit more serious than that of BadHare's because I expand the tree dynamically depending on other actions the user performs.. So the user will see instance of the message every time she aforementioned the aforementioned task.
    Last edited by openuser; 27th July 2010 at 18:09.

Similar Threads

  1. Problem at time compilation in traslation of language
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2007, 14:18
  2. Paint XP radio button to pixmap
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2006, 21:15
  3. How to paint a selection rectangle on a pixmap?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 8th January 2006, 19:52

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.