PDA

View Full Version : QLabel on top of a QGLWidget background issue



Rayven
4th April 2011, 19:56
I am attempting to make a radial menu expander in a corner of an QGLWidget scene by subclassing a QLabel, adding a pixmap, adding mousePressEvent and mouseReleaseEvent overrides and move(ing) the label to the corner of the widget (i.e. not adding into a layout). I do not want to add in as an object in my GL scene since the popup menus that will appear need to be generic and very user definable.



QPixmap pix( ":/files/add_button" );
QLabel *menuWidget = new QLabel( glWidget );
menuWidget->setAutoFillBackground( false ); // Should not be needed
menuWidget->setPixmap( pix );

menuWidget->move( 100, 100 );


The add_button pixmap is a PNG with a transparent background.

The image displays in the proper place, but the background color of the image is black (incidently the same color as the qglClearColor) instead of clear. Secondly, when I click on the image and replace with a larger image, I can see the image change, but its size does not.

Any thoughts? Sorry no code to post, on a different system.

high_flyer
5th April 2011, 11:50
The image displays in the proper place, but the background color of the image is black (incidently the same color as the qglClearColor) instead of clear.
That is because the GL content is not in Qt context, so Qt does not know about it anything, which means, you QLabel can't know which background it should fill - so its black.

Secondly, when I click on the image and replace with a larger image, I can see the image change, but its size does not.

You have to resize the QLabel to flt your image.

Rayven
5th April 2011, 15:16
That is because the GL content is not in Qt context, so Qt does not know about it anything, which means, you QLabel (http://doc.qt.nokia.com/latest/qlabel.html) can't know which background it should fill - so its black.

Is there anyway to switch the QLabels context to GLs?

JohannesMunk
5th April 2011, 15:27
You could use a graphicsscene with a glwidget as viewport. Put your GL calls in the scenes.drawBackground and put your code inbetween painter.beginNativePainting() and painter.endNativePainting().. Add your pixmap as a qgraphicspixmapitem.

Or you draw the pixmap directly to your glwidget instead of using a label. Use QPainter::drawPixmap .. http://doc.qt.nokia.com/latest/qglwidget.html#painting-techniques

HIH

Johannes

Rayven
5th April 2011, 18:26
You could use a graphicsscene with a glwidget as viewport. Put your GL calls in the scenes.drawBackground and put your code inbetween painter.beginNativePainting() and painter.endNativePainting().. Add your pixmap as a qgraphicspixmapitem.

Or you draw the pixmap directly to your glwidget instead of using a label. Use QPainter::drawPixmap .. http://doc.qt.nokia.com/latest/qglwidget.html#painting-techniques

I am trying to keep it out of the GL widget if possible for reuseability, but if I cannot I will probably go the QGraphicsView route. Is there any benefit to putting the GL calls in drawBackground vs. paintEvent in QGraphicsView?

JohannesMunk
5th April 2011, 18:34
As the view is conceptually only the display of the scene which contains the content, you would break that concept, if you put content into the view.

As you want your item to be on top of your other gl stuff, I though the background would be appropriate for it.

Joh