[Qt-interest] QGraphicsView Transformations

Ollie saurero at gmail.com
Thu Jun 18 02:52:28 CEST 2009


Hi,

I'm using QGraphicsView to render QGraphicsItems of a
QGraphicsScene.The whole QGraphicsScene can be manipulated from the
QGraphicsView using scale(.), rotate(.), shear (.) and translate(.) .
Though when calling translate(.) the items in QGraphicsScene do not
move, while rotation, scale and shear work properly.
Find below a minimal example illustrating the problem. Am I missing
something..? I'm using Qt 4.5 on winxp.

Any suggestions are greatly received.

Thanks
Olivier

/* sample code */
#include <QApplication>
#include <QGraphicsView>
#include <QKeyEvent>

class Viewer:
		public QGraphicsView
{
public:
	Viewer(){};
	~Viewer(){};
	
protected:
	void keyPressEvent(QKeyEvent *ke){
		switch(ke->key()){
			case Qt::Key_T:
				translate(10, 0);
				break;
			case Qt::Key_R:
				rotate(45);
				break;
			case Qt::Key_S:
				scale(1.1, 1.1);
			case Qt::Key_X:
				shear(0.1, 0.1);
			default:
				QWidget::keyPressEvent(ke);
		}
	}
};

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);

	Viewer viewer;
	viewer.setScene(new QGraphicsScene());
	viewer.scene()->addRect(100, 100, 50, 50);
		
	viewer.resize(640, 480);
	viewer.show();

	return app.exec();
}



More information about the Qt-interest-old mailing list