QLabel image on center of the widget
Hi, I'm trying to draw an image on the center of a widget and I thought that the best way of doing that would be using
QPixmap logotype(":/logotype.jpg"); QLabel *logotypeLabel = new QLabel; logotypeLabel->setPixmap(logotype);
Now I want to know how to add it to the center (horizontally and vertically) of the main widget?
And is it the best way for drawing an image on a widget? Or it's better using OpenGL or QPainter, or what is the fastest?
Add a layout to centralwidget and it can be centered
Make sure to set labels
OpenGl can paint muh faster but you cant just use widgets inside a openGL context
so the best way really depends on what goals you have.
QLabel paints the pixmap with painter.
I was thinking about using OpenGL to draw as I have the code already but I noticed that
QOpenGLWidgetlags bit when resizing the window and
QWidgetdoesn't, I don't know why.
Well the openGL have far more to handle when resizing the draw area and
a QWidget is much "thinner" in comparison.
But unless you need something else from openGL or wants to draw many images at high speed, opengl migbt be a bit overkill.
@mrjj Actually I was thinking about using
QOpenGLWidgetto render videos using libvlc, the libvlc asks for a
window handlerfrom a widget and I thought that
QOpenGLWidgetwould be faster for rendering, but I don't know why but the resizing is kinda lagging.
It might draw faster, but normally libVLC alone does it ok.
Its very hard to guess at the lagging with no code. But often
#d application suffer the same so its quite common.
@mrjj It doesn't have a code to be honest, it's just an instance of
QOpenGLWidgetadded to a layout and that layout added to the main widget. When I start resizing randomly I can feel that it starts lagging, when I change from
QWidgetit doesn't lag anymore.
Ok, you can they the Hello GL2 Example
and see if that lags too
I noticed that libvlc allows to create a kind of custom renderer, this example uses SDL using OpenGL, it seems that it gets events that come from libvlc and renders by itself, although it seems to be complicated and I don't think that it's totally necessary.
I can't run Hello GL 2, I get this message:
The program has unexpectedly finished.MSVC 2015 64bit. (It worked on release mode but not on debug).
Really I just ran it to see if it would lag when resized :)
Are you gfx drivers up to date etc?
@mrjj It's not lagging, weird, perhaps it's some kind of attribute/configuration, I will investigate tho.