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 Updated to NodeBB v4.3 + New Features

QImage

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 911 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.
  • S Offline
    S Offline
    satyanarayana143
    wrote on 2 Nov 2018, 06:48 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 Nov 2018, 07:19 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 2 Nov 2018, 07:29 last edited by
        #3

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

        M 1 Reply Last reply 2 Nov 2018, 07:31
        0
        • S satyanarayana143
          2 Nov 2018, 07:29

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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 2 Nov 2018, 07:31 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 2 Nov 2018, 07:39 last edited by
            #5

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

            M 1 Reply Last reply 2 Nov 2018, 07:53
            0
            • S satyanarayana143
              2 Nov 2018, 07:39

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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 2 Nov 2018, 07:53 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 2 Nov 2018, 08:30
              0
              • M mrjj
                2 Nov 2018, 07:53

                @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 2 Nov 2018, 08:30 last edited by
                #7

                @mrjj

                can you send the code

                M 1 Reply Last reply 2 Nov 2018, 08:39
                0
                • S satyanarayana143
                  2 Nov 2018, 08:30

                  @mrjj

                  can you send the code

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 2 Nov 2018, 08:39 last edited by
                  #8

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

                  1 Reply Last reply
                  0

                  1/8

                  2 Nov 2018, 06:48

                  • Login

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