[Qt-interest] custom widgets and OpenGL
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Fri Nov 12 14:41:31 CET 2010
On 2010-11-12 Tyler Tyler Daniel wrote:
> ...
> So maybe my question should have been: is anyone using a QGLWidget subclass
> as a top-level widget/window in full-screen mode with no problems?
I quickly modified the {QTDIR}/examples/opengl/hellogl example
Change the main.cpp the following way:
#include <QApplication>
#include <QDesktopWidget>
#include "glwidget.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
GLWidget glWidget;
glWidget.setWindowState(Qt::WindowFullScreen);
glWidget.show();
return app.exec();
}
It renders the "Qt" logo perfectly in full-screen, and I don't see any flicker whatsoever when ALT-Tabbing to other windows or rotating the logo.
However that's on some Lenovo Thinkpad laptop on Windows XP SP3, Qt 4.7.0 - with two screens attached or undocked on the laptop screen only.
Try the above example on Windows 7, does it work? If not, what if you try it on some other Windows 7 setup (different graphic card)?
> Yep. This is what I'm doing now as a test. It works, but it feels a little too
> complex.
As I said, I have no practical experience with QGraphicsScene/View, but to my understanding it offers already lot of functionality like "determining the position of a given element in the scene", mouse handling...
However you could also go the http://doc.trolltech.com/4.7/qwidget.html#render approach which allows you to render the QWidget based widget (a QDialog, for example) into a QPixmap. Once you have this QPixmap you could convert it to a texture. This texture would have to be updated each time you hover over a button (as to see the "hover" effect etc.). Also the mouse handling would be entirely up to your QGLWidget (determine where the widget is located in screen coordinates etc.).
To my understanding all this is already available in QGraphicsModel, which with the help of "widget proxies" already figures out for you which widget has been clicked (not sure though, I did not study the mouse handling to closely in the example provided in the Qt Quarterly 26 example).
> I don't have a lot of items that I want Qt to manage for me. Also it feels
> a little strange to be doing the rendering in the scene and not the view, but that's a
> different discussion.
Well, think of "rendering" as in "changing the model", so when you say e.g.:
QGraphicsScene::addLine()
it really means "change the model by adding a line to it" (in contrast to the QPainter API, where it really means "draw a line" ;). So the QGraphicsScene is really the Model and the QGraphicsView the... View ;) (when thinking in MVC patterns).
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list