Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, June 2007
Issue when transforming 4.3 QGView without scrollbars vs. 4.2.3


Message 1 in thread

Hi,

I am trying to figure out why one of my programs stopped behaving as intended, 
after having switched from Qt 4.2.3 to 4.3.

To narrow down the issue, I wrote a small test application that scrolls to the 
right when the user LMB drags on the GraphicsView widget. The 
QAbstractScrollArea's horizontal scroll bar is intentionally hidden as 
scrolling is to be done by transforming the view (camera).

The issue is that this application works under 4.2.3 but not under 4.3 with 
the exact same code. It only works under 4.3 if I comment out the command for 
hiding the horizontal scroll bar but this is not what I want.

How can I get this fixed under 4.3?

----- (main.cpp)

#include <QtGui>
#include <QDebug>
#include "GView.h"

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

	QGraphicsScene scene;

	for (int var = 0; var < 10; ++var) {
		QGraphicsRectItem *rect = new QGraphicsRectItem;
		rect->setRect(0, 0, 50-var, 100);
		rect->translate(var*55,0);
		scene.addItem(rect);
	}
	
	GView view;
	view.setScene(&scene);
	view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	view.setTransformationAnchor(QGraphicsView::NoAnchor);
	view.resize(400, 300);
	view.show();
	
	return app.exec();
}

----- (GView.cpp)

#include "GView.h"

void GView::mouseMoveEvent(QMouseEvent *event)
{
	// continue only if the left button was used
	if (!(event->buttons() & Qt::LeftButton))
		return;
	
	qDebug() << "drag";
	
    QMatrix qm = matrix();
    qm.setMatrix(qm.m11(), qm.m12(), qm.m21(), qm.m22(), qm.dx()-10, qm.dy());
    setMatrix(qm);
}

----- (GView.h)

#ifndef GVIEW_H_
#define GVIEW_H_

class GView : public QGraphicsView
{
public:
	GView(QWidget *parent = 0) {}
	virtual ~GView() {}
	void mouseMoveEvent(QMouseEvent *event);
};

#endif /*GVIEW_H_*/

-----

Thank you.

Regards,
-- 
 [ signature omitted ]