[Qt-interest] QPainter

John McClurkin jwm at nei.nih.gov
Thu Mar 26 13:26:26 CET 2009


Hi all,
	I see from the examples and from Qt source code that, when an object 
needs to be painted, a QPainter object is created inside the 
QPaintEvent. Either
	myWidget::paintEvent(QPaintEvent *pe)
	{
		QPainter painter(this);
			.
			.
			.
	}
or
	myWidget::paintEvent(QPaintEvent *pe)
	{
		QPainter painter;
		painter.begin(this);
			.
			.
			.
		painter.end();
	}

Are there any advantages or disadvantages to having a QPainter object as 
a class member, created when an instance of the class is instantiated, 
then just calling begin and end in the paint event?
	class myWidget : public QWidget
	{
		.
		.
		.
	  private:
		void paintEvent(QPaintEvent *pe);
		QPainter painter;
	};

	myWidget::paintEvent(QPaintEvent *pe)
	{
		painter.begin(this);
			.
			.
			.
		painter.end();
	}

Thanks



More information about the Qt-interest-old mailing list