[Qt-interest] Render Widgets inside QGLWidget

Ollie saurero at gmail.com
Fri May 29 12:58:15 CEST 2009


Hi,

I'm using QGraphicsView with QGLWidget and QGraphicsScene to display
widgets over an opengl scene. One of the widgets is a QDialog holding
a QGraphicsView together with  QGraphicsScene and some QGraphicsItems
(see minimal sample code below). With this setup I encounter two
problems.

1) When moving the QDialog widget, the QGraphicsItems inside the
QDialog stay at there position and don't move. Though, when scaling
the widget all QGraphicsItems do adapt there position...

2) The mouse sensitive area of the QGraphicsItem inside the QDialog
is not aligned with its graphical representation. One needs to click a
couple of pixels below or next to the item to properly select it. Is
Painter missing some translation operation when drawing the items ..?

Is there a better way to render Widgets over a QGLWidget?

Any pointers or suggestions are greatly received.

Thanks
Ollie

/* sample code */

#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QDialog>
#include <QVBoxLayout>
#include <QGLWidget>


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

	QGraphicsView *view1 = new QGraphicsView,
		*view2 = new QGraphicsView;
	QGraphicsScene *scene1 = new QGraphicsScene,
		*scene2 = new QGraphicsScene;

	QGraphicsItem* item = scene2->addRect(QRect(0,0,10,10));		
	item->setFlag(item->ItemIsMovable);

	view2->setScene(scene2);
	QDialog dialog;
	
	dialog.setLayout(new QVBoxLayout);
	dialog.layout()->addWidget(view2);

	//dialog.show();

	scene1->addWidget(&dialog);
	
	view1->setViewport(new QGLWidget);
	view1->setScene(scene1);

	view1->show();
	return app.exec();
}



More information about the Qt-interest-old mailing list