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 not starting from 0,0
Forum Updated to NodeBB v4.3 + New Features

QLabel not starting from 0,0

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 5 Posters 3.2k 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #3

    Check the margins in layouts and in QLabel, too.

    Also, see if the margin is not due to layout stretching (if the window is much bigger than your QLabel, the label will be stretched to fill the window, or if it is fixed size it can center itself).

    (Z(:^

    A 1 Reply Last reply
    1
    • sierdzioS sierdzio

      Check the margins in layouts and in QLabel, too.

      Also, see if the margin is not due to layout stretching (if the window is much bigger than your QLabel, the label will be stretched to fill the window, or if it is fixed size it can center itself).

      A Offline
      A Offline
      Arqam
      wrote on last edited by
      #4

      @sierdzio @m-sue All my values are as per default.

      Yeah I have fixed my window size as 700,700.
      My layoutLeftMargin is also set as 0.

      My UI window part : https://pastebin.com/TAEBh1Wx

      0_1502970009975_Screen Shot 2017-08-17 at 5.09.12 PM.png

      Venkatesh VV m.sueM 2 Replies Last reply
      0
      • A Arqam

        @sierdzio @m-sue All my values are as per default.

        Yeah I have fixed my window size as 700,700.
        My layoutLeftMargin is also set as 0.

        My UI window part : https://pastebin.com/TAEBh1Wx

        0_1502970009975_Screen Shot 2017-08-17 at 5.09.12 PM.png

        Venkatesh VV Offline
        Venkatesh VV Offline
        Venkatesh V
        wrote on last edited by
        #5

        @Arqam

        Hi,
        use setContentsMargin(0,0,0,0); method for both main layout and label.

        A 1 Reply Last reply
        0
        • A Arqam

          @sierdzio @m-sue All my values are as per default.

          Yeah I have fixed my window size as 700,700.
          My layoutLeftMargin is also set as 0.

          My UI window part : https://pastebin.com/TAEBh1Wx

          0_1502970009975_Screen Shot 2017-08-17 at 5.09.12 PM.png

          m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #6

          Hi @Arqam

          Try to change this line<layoutdefault spacing="6" margin="11"/>

          -Michael.

          A 1 Reply Last reply
          0
          • m.sueM m.sue

            Hi @Arqam

            Try to change this line<layoutdefault spacing="6" margin="11"/>

            -Michael.

            A Offline
            A Offline
            Arqam
            wrote on last edited by
            #7

            @m.sue said in QLabel not starting from 0,0:

            <layoutdefault spacing="6" margin="11"/>

            That section has a GUI and the XML is not editable. Any way that change can be done?

            m.sueM 1 Reply Last reply
            0
            • A Arqam

              @m.sue said in QLabel not starting from 0,0:

              <layoutdefault spacing="6" margin="11"/>

              That section has a GUI and the XML is not editable. Any way that change can be done?

              m.sueM Offline
              m.sueM Offline
              m.sue
              wrote on last edited by m.sue
              #8

              Hi @Arqam

              I thought you wrote the XML. Then see above:

              @Venkatesh-V said in QLabel not starting from 0,0:

              use setContentsMargin(0,0,0,0); method for both main layout and label.

              -Michael.

              1 Reply Last reply
              0
              • Venkatesh VV Venkatesh V

                @Arqam

                Hi,
                use setContentsMargin(0,0,0,0); method for both main layout and label.

                A Offline
                A Offline
                Arqam
                wrote on last edited by
                #9

                @Venkatesh-V @m-sue
                How can I do that, I know for my QLabel containing the image I can do
                ui->label_image->setContentsMargins(0,0,0,0);

                Constructor :

                MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                {
                    this->setFixedSize(700,700);
                    ui->setupUi(this);
                    ui->label_image->setContentsMargins(0,0,0,0);
                }
                

                So how can we change for main layout also, as just changing the value for label didn't do any thing.

                1 Reply Last reply
                0
                • Vinod KuntojiV Offline
                  Vinod KuntojiV Offline
                  Vinod Kuntoji
                  wrote on last edited by
                  #10

                  @Arqam ,

                  First add your label to main layout and then call,

                  mainLayout->setContentMargins(-1,-1,-1,-1);

                  C++, Qt, Qt Quick Developer,
                  PthinkS, Bangalore

                  A 1 Reply Last reply
                  0
                  • Vinod KuntojiV Vinod Kuntoji

                    @Arqam ,

                    First add your label to main layout and then call,

                    mainLayout->setContentMargins(-1,-1,-1,-1);

                    A Offline
                    A Offline
                    Arqam
                    wrote on last edited by Arqam
                    #11

                    @Vinod-Kuntoji
                    I did :

                    this->setContentsMargins(-1,-1,-1,-1);
                    ui->label_image->setContentsMargins(0,0,0,0);
                    

                    What it did is just that a bit to the left (and other direction) the margin is reduced.
                    When I give the default value i.e. -11 that is given in the XML then it starts from the leftmost region.
                    But when given for the top position i.e (-11,-11,0,0) QLabel doesn't start from the topmost part.

                    1 Reply Last reply
                    0
                    • Vinod KuntojiV Offline
                      Vinod KuntojiV Offline
                      Vinod Kuntoji
                      wrote on last edited by
                      #12

                      @Arqam ,

                      I tried like this.

                      MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                      {
                      ui->setupUi(this);
                      mLabel = new QLabel(this);
                      mLayout = new QVBoxLayout(this);

                      QPixmap pix(":/image.PNG");
                      mLabel->setPixmap(pix);
                      
                      mLayout->addWidget(mLabel);
                      

                      // mLayout->setContentsMargins(0,0,0,0);
                      mLayout->setMargin(0);
                      mLayout->setSpacing(0);
                      mLayout->setAlignment(mLabel,Qt::AlignTop);
                      QWidget *widget = new QWidget(this);
                      widget->setLayout(mLayout);

                      this->setCentralWidget(widget);
                      

                      }

                      There is a toolbar on top of the label, thats why it is showing some space on top of label. If you dont want the toolbar then remove it.

                      C++, Qt, Qt Quick Developer,
                      PthinkS, Bangalore

                      A 1 Reply Last reply
                      0
                      • Vinod KuntojiV Vinod Kuntoji

                        @Arqam ,

                        I tried like this.

                        MainWindow::MainWindow(QWidget *parent) :
                        QMainWindow(parent),
                        ui(new Ui::MainWindow)
                        {
                        ui->setupUi(this);
                        mLabel = new QLabel(this);
                        mLayout = new QVBoxLayout(this);

                        QPixmap pix(":/image.PNG");
                        mLabel->setPixmap(pix);
                        
                        mLayout->addWidget(mLabel);
                        

                        // mLayout->setContentsMargins(0,0,0,0);
                        mLayout->setMargin(0);
                        mLayout->setSpacing(0);
                        mLayout->setAlignment(mLabel,Qt::AlignTop);
                        QWidget *widget = new QWidget(this);
                        widget->setLayout(mLayout);

                        this->setCentralWidget(widget);
                        

                        }

                        There is a toolbar on top of the label, thats why it is showing some space on top of label. If you dont want the toolbar then remove it.

                        A Offline
                        A Offline
                        Arqam
                        wrote on last edited by Arqam
                        #13

                        @Vinod-Kuntoji said in QLabel not starting from 0,0:

                        this->setCentralWidget(widget);

                        My widget main window is not having a toolbar, it was having a status bar which I removed.
                        The structure of my window is like this :

                        ![alt text](0_1503035481018_Screen Shot 2017-08-17 at 6.02.39 PM.png image url)

                        If going by your example my mLayout should be Central Widget?

                        1 Reply Last reply
                        0
                        • Vinod KuntojiV Offline
                          Vinod KuntojiV Offline
                          Vinod Kuntoji
                          wrote on last edited by
                          #14

                          @Arqam ,

                          Please mark your issue as solved.

                          C++, Qt, Qt Quick Developer,
                          PthinkS, Bangalore

                          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