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. QImage
Forum Update on Monday, May 27th 2025

QImage

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 894 Views
  • 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.
  • S Offline
    S Offline
    satyanarayana143
    wrote on last edited by
    #1

    0_1541141168940_Camera.png

    Hi friends,

    I am Qlabel in Qwidget to display image but in Qlabel image left side gap is more than right size how to center can anbody tell the solution.

     const QPixmap pix = QPixmap::fromImage(image);
    const QSize size = ui->Image_Label->size();  
    
    //modified on 23/10/2018
    ui->Image_Label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    ui->Image_Label->setPixmap(pix.scaled(size,Qt::KeepAspectRatio));
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      When do you call the code ?
      The ui->Image_Label should be fully visible before you take its
      size as layout calculation is deferred until widget is visible.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        satyanarayana143
        wrote on last edited by
        #3

        In Qwiget i put QLabel with gridlayout in ui form at starting i am showing widget.

        mrjjM 1 Reply Last reply
        0
        • S satyanarayana143

          In Qwiget i put QLabel with gridlayout in ui form at starting i am showing widget.

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

          @satyanarayana143
          "at starting" means in Mainwindows constructor ?
          Try to do same code from a button and see if it then works as expected.
          if it does, it means, you are doing taking size of Label when its not fully layouted yet.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            satyanarayana143
            wrote on last edited by
            #5

            I am displaying when checkbox checked in ui as above image.

            mrjjM 1 Reply Last reply
            0
            • S satyanarayana143

              I am displaying when checkbox checked in ui as above image.

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

              @satyanarayana143
              So when you run code, the QLabel is fully visible ?
              Sorry , i cannot guess what else could be wrong.
              It centers as expected here
              alt text

              S 1 Reply Last reply
              0
              • mrjjM mrjj

                @satyanarayana143
                So when you run code, the QLabel is fully visible ?
                Sorry , i cannot guess what else could be wrong.
                It centers as expected here
                alt text

                S Offline
                S Offline
                satyanarayana143
                wrote on last edited by
                #7

                @mrjj

                can you send the code

                mrjjM 1 Reply Last reply
                0
                • S satyanarayana143

                  @mrjj

                  can you send the code

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

                  @satyanarayana143
                  Sure
                  https://www.dropbox.com/s/fladys1ao8cj5gq/centerlabel.zip?dl=0

                  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