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. Layout Alignmet not respected

Layout Alignmet not respected

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 260 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
    Simof
    wrote on last edited by
    #1

    Dear all,

    I don't understand because my custom class that inherit from QLabel not respect the Center Alignment.

    2021-07-01 12_23_57-Window.png

    LanguagesMenu::LanguagesMenu(QWidget *parent) : SkeletronView(parent)
    {
        this->setObjectName("LanguagesMenu");
    
        QWidget* widget = new QWidget();
        widget->setMaximumSize(600, 400);
    
        itBtn = new ZoomLabel(":/Images/Flags/itFlag.png", "itFlag");
    
        enBtn = new ZoomLabel(":/Images/Flags/enFlag.png", "enFlag");
    
        frBtn = new ZoomLabel(":/Images/Flags/frFlag.png", "frFlag");
    
        QVBoxLayout* layout = new QVBoxLayout(widget);
        layout->addWidget(itBtn, Qt::AlignHCenter);
        layout->addWidget(enBtn, Qt::AlignHCenter);
        layout->addWidget(frBtn, Qt::AlignHCenter);
    
        layout->setContentsMargins(10, 10, 10, 10);
        layout->setSpacing(1);
    
        widget->setLayout(layout);
    
        hideSettingsBtn();
    //    hideBackBtn();
        hideForwardBtn();
    //    hideHomeBtn();
    
        handler();
    
        SkeletronView::setCentralWidget(widget);
    
    }
    
    void LanguagesMenu::handler(void)
    {
        itBtn->setMaximumWidth(400);
        itBtn->setAlignment(Qt::AlignCenter);
    
        enBtn->setMaximumWidth(500);
        enBtn->setAlignment(Qt::AlignCenter);
    
        frBtn->setMaximumWidth(400);
        frBtn->setAlignment(Qt::AlignCenter);
    
    }
    
    jsulmJ 1 Reply Last reply
    0
    • S Simof

      Dear all,

      I don't understand because my custom class that inherit from QLabel not respect the Center Alignment.

      2021-07-01 12_23_57-Window.png

      LanguagesMenu::LanguagesMenu(QWidget *parent) : SkeletronView(parent)
      {
          this->setObjectName("LanguagesMenu");
      
          QWidget* widget = new QWidget();
          widget->setMaximumSize(600, 400);
      
          itBtn = new ZoomLabel(":/Images/Flags/itFlag.png", "itFlag");
      
          enBtn = new ZoomLabel(":/Images/Flags/enFlag.png", "enFlag");
      
          frBtn = new ZoomLabel(":/Images/Flags/frFlag.png", "frFlag");
      
          QVBoxLayout* layout = new QVBoxLayout(widget);
          layout->addWidget(itBtn, Qt::AlignHCenter);
          layout->addWidget(enBtn, Qt::AlignHCenter);
          layout->addWidget(frBtn, Qt::AlignHCenter);
      
          layout->setContentsMargins(10, 10, 10, 10);
          layout->setSpacing(1);
      
          widget->setLayout(layout);
      
          hideSettingsBtn();
      //    hideBackBtn();
          hideForwardBtn();
      //    hideHomeBtn();
      
          handler();
      
          SkeletronView::setCentralWidget(widget);
      
      }
      
      void LanguagesMenu::handler(void)
      {
          itBtn->setMaximumWidth(400);
          itBtn->setAlignment(Qt::AlignCenter);
      
          enBtn->setMaximumWidth(500);
          enBtn->setAlignment(Qt::AlignCenter);
      
          frBtn->setMaximumWidth(400);
          frBtn->setAlignment(Qt::AlignCenter);
      
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Simof said in Layout Alignmet not respected:

      layout->addWidget(itBtn, Qt::AlignHCenter);

      Second parameter is actually stretch: https://doc.qt.io/qt-5/qboxlayout.html#addWidget

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        My problem is not the stretch, the goal is align at horizontally center of the parent widget all labels.

        2021-07-01 12_23_57-Window.png

        jsulmJ 1 Reply Last reply
        0
        • S Simof

          My problem is not the stretch, the goal is align at horizontally center of the parent widget all labels.

          2021-07-01 12_23_57-Window.png

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Simof My point is that alignment is the THIRD parameter, not second.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          2
          • jsulmJ jsulm

            @Simof My point is that alignment is the THIRD parameter, not second.

            S Offline
            S Offline
            Simof
            wrote on last edited by
            #5

            @jsulm said in Layout Alignmet not respected:

            @Simof My point is that alignment is the THIRD parameter, not second.

            Thanks, I rectified the error like you suggest and next I set "Fixed" the size policy and the issues was solved

            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