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
QLabel
withsetPixmap
.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?
-
Hi
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.
-
Hi
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
QOpenGLWidget
to render videos using libvlc, the libvlc asks for awindow handler
from a widget and I thought thatQOpenGLWidget
would be faster for rendering, but I don't know why but the resizing is kinda lagging. -
@mrjj It doesn't have a code to be honest, it's just an instance of
QOpenGLWidget
added 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 fromQOpenGLWidget
toQWidget
it doesn't lag anymore.@ edit
libvlc reference: https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html#ga0ee3abb85cd9735fdeace4882eb711f3
-
@Dohisev
Ok, you can they the Hello GL2 Example
and see if that lags too
http://doc.qt.io/qt-5/qtopengl-hellogl2-example.html -
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).