Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLabel image on center of the widget
Forum Updated to NodeBB v4.3 + New Features

QLabel image on center of the widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 2 Posters 6.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dohisev
    wrote on last edited by Dohisev
    #1

    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 with setPixmap .

    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Add a layout to centralwidget and it can be centered
      Make sure to set labels
      alt text
      alt text

      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.

      1 Reply Last reply
      5
      • D Offline
        D Offline
        Dohisev
        wrote on last edited by
        #3

        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 and QWidget doesn't, I don't know why.

        mrjjM 1 Reply Last reply
        0
        • D Dohisev

          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 and QWidget doesn't, I don't know why.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          D 1 Reply Last reply
          0
          • mrjjM mrjj

            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.

            D Offline
            D Offline
            Dohisev
            wrote on last edited by
            #5

            @mrjj Actually I was thinking about using QOpenGLWidget to render videos using libvlc, the libvlc asks for a window handler from a widget and I thought that QOpenGLWidget would be faster for rendering, but I don't know why but the resizing is kinda lagging.

            mrjjM 1 Reply Last reply
            0
            • D Dohisev

              @mrjj Actually I was thinking about using QOpenGLWidget to render videos using libvlc, the libvlc asks for a window handler from a widget and I thought that QOpenGLWidget would be faster for rendering, but I don't know why but the resizing is kinda lagging.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Dohisev

              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.

              D 1 Reply Last reply
              0
              • mrjjM mrjj

                @Dohisev

                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.

                D Offline
                D Offline
                Dohisev
                wrote on last edited by Dohisev
                #7

                @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 from QOpenGLWidget to QWidget it doesn't lag anymore.

                @ edit

                libvlc reference: https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html#ga0ee3abb85cd9735fdeace4882eb711f3

                mrjjM 1 Reply Last reply
                0
                • D Dohisev

                  @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 from QOpenGLWidget to QWidget it doesn't lag anymore.

                  @ edit

                  libvlc reference: https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html#ga0ee3abb85cd9735fdeace4882eb711f3

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  @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

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Dohisev
                    wrote on last edited by Dohisev
                    #9

                    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).

                    mrjjM 1 Reply Last reply
                    0
                    • D Dohisev

                      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).

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Dohisev
                      Really I just ran it to see if it would lag when resized :)
                      Are you gfx drivers up to date etc?

                      D 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @Dohisev
                        Really I just ran it to see if it would lag when resized :)
                        Are you gfx drivers up to date etc?

                        D Offline
                        D Offline
                        Dohisev
                        wrote on last edited by
                        #11

                        @mrjj It's not lagging, weird, perhaps it's some kind of attribute/configuration, I will investigate tho.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved