Unsolved 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.
-
I was thinking about using OpenGL to draw as I have the code already but I noticed that
QOpenGLWidget
lags bit when resizing the window andQWidget
doesn't, I don't know why. -
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. -
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
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). -
@Dohisev
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.