PDA

View Full Version : QPainter::begin: Cannot paint on a null pixmap



sabeesh
17th August 2007, 12:33
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..............

wysota
17th August 2007, 13:31
Which Qt release do you use?

BadHare
17th June 2009, 19:46
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:


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

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!

Lykurg
17th June 2009, 20:00
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.

BadHare
17th June 2009, 21:09
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!

openuser
27th July 2010, 19:03
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.