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. When you setText of the button, the Geometry changes.

When you setText of the button, the Geometry changes.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 939 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
    void wFunctionMenu::BtnResize()
    {
    	QRect rect(
    		this->ui.verticalLayout->contentsMargins().left(),
    		this->ui.verticalLayout->contentsMargins().top(),
    		this->size().width() - (this->ui.verticalLayout->contentsMargins().left() + this->ui.verticalLayout->contentsMargins().right()),
    		(this->size().height() - (this->ui.verticalLayout->contentsMargins().bottom() + this->ui.verticalLayout->spacing() * m_nBtnCnt - 1)) / m_nBtnCnt
    	);
    
    		this->ui.btn_CnP	->setGeometry(rect);
    		this->ui.btn_NewF	->setGeometry(rect.x(),	this->ui.btn_CnP->geometry().y() + rect.height() +	this->ui.verticalLayout->spacing(), rect.width(), rect.height());
    		this->ui.btn_Rename	->setGeometry(rect.x(), this->ui.btn_NewF->geometry().y() + rect.height() + this->ui.verticalLayout->spacing(), rect.width(), rect.height());
    		this->ui.btn_Delete	->setGeometry(rect.x(), this->ui.btn_Rename->geometry().y() + rect.height() + this->ui.verticalLayout->spacing(), rect.width(), rect.height());
    	
    }
    

    In class Initialize, the position of the button is specified through the setGeometry function.
    And change the text of the button according to the external flag.
    When you change the button text, the geometry changes to the layout set in Qt Designer. The button size is also changed to the original size.

    Why does this happen? Is it a bug?

    jsulmJ 1 Reply Last reply
    0
    • I IknowQT

      @jsulm
      @JonB

      Are you saying you have to manually create the object to use the geometry?
      I'll test it with the object creation method and tell you the result

      The question seems to have been understood if the set geometry did not work even during Initialize.
      However, the question remains as to whether the geometry works when initialized and returns to the original state when setText is executed.

      One of the things I tested was calling the geometry defined function again after calling setText. Nevertheless, it was not in the desired position.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #7

      @IknowQT
      I would not assume anything if you set geometry when a widget is on a layout.

      Further, even without layouts, I would not rely on geometry returning anything sensible/correct until the widget has been shown.

      1 Reply Last reply
      2
      • I IknowQT
        void wFunctionMenu::BtnResize()
        {
        	QRect rect(
        		this->ui.verticalLayout->contentsMargins().left(),
        		this->ui.verticalLayout->contentsMargins().top(),
        		this->size().width() - (this->ui.verticalLayout->contentsMargins().left() + this->ui.verticalLayout->contentsMargins().right()),
        		(this->size().height() - (this->ui.verticalLayout->contentsMargins().bottom() + this->ui.verticalLayout->spacing() * m_nBtnCnt - 1)) / m_nBtnCnt
        	);
        
        		this->ui.btn_CnP	->setGeometry(rect);
        		this->ui.btn_NewF	->setGeometry(rect.x(),	this->ui.btn_CnP->geometry().y() + rect.height() +	this->ui.verticalLayout->spacing(), rect.width(), rect.height());
        		this->ui.btn_Rename	->setGeometry(rect.x(), this->ui.btn_NewF->geometry().y() + rect.height() + this->ui.verticalLayout->spacing(), rect.width(), rect.height());
        		this->ui.btn_Delete	->setGeometry(rect.x(), this->ui.btn_Rename->geometry().y() + rect.height() + this->ui.verticalLayout->spacing(), rect.width(), rect.height());
        	
        }
        

        In class Initialize, the position of the button is specified through the setGeometry function.
        And change the text of the button according to the external flag.
        When you change the button text, the geometry changes to the layout set in Qt Designer. The button size is also changed to the original size.

        Why does this happen? Is it a bug?

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

        @IknowQT said in When you setText of the button, the Geometry changes.:

        the geometry changes to the layout set in Qt Designer

        If you set the geometry manually why did you put the button into a layout?

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

        I 1 Reply Last reply
        2
        • jsulmJ jsulm

          @IknowQT said in When you setText of the button, the Geometry changes.:

          the geometry changes to the layout set in Qt Designer

          If you set the geometry manually why did you put the button into a layout?

          I Offline
          I Offline
          IknowQT
          wrote on last edited by IknowQT
          #3

          @jsulm

          problem.gif

          This is to make it easier to manage without creating an object. I don't think that would be a problem.

          JonBJ jsulmJ 2 Replies Last reply
          0
          • I IknowQT

            @jsulm

            problem.gif

            This is to make it easier to manage without creating an object. I don't think that would be a problem.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @IknowQT said in When you setText of the button, the Geometry changes.:

            I don't think that would be a problem.

            Based on what? You think it is a bug in Qt instead? How do putting a widget on a layout, which controls its position, and setting its geometry, which sets its position, interact with each other?

            1 Reply Last reply
            0
            • I IknowQT

              @jsulm

              problem.gif

              This is to make it easier to manage without creating an object. I don't think that would be a problem.

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

              @IknowQT said in When you setText of the button, the Geometry changes.:

              This is to make it easier to manage without creating an object

              It still does not make sence to put widgets into a layout if you want to set their geometry manually.
              Why don't you use layouts? What is the benefit doing positioning/sizing manually?

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

              I 1 Reply Last reply
              0
              • jsulmJ jsulm

                @IknowQT said in When you setText of the button, the Geometry changes.:

                This is to make it easier to manage without creating an object

                It still does not make sence to put widgets into a layout if you want to set their geometry manually.
                Why don't you use layouts? What is the benefit doing positioning/sizing manually?

                I Offline
                I Offline
                IknowQT
                wrote on last edited by IknowQT
                #6

                @jsulm
                @JonB

                Are you saying you have to manually create the object to use the geometry?
                I'll test it with the object creation method and tell you the result

                The question seems to have been understood if the set geometry did not work even during Initialize.
                However, the question remains as to whether the geometry works when initialized and returns to the original state when setText is executed.

                One of the things I tested was calling the geometry defined function again after calling setText. Nevertheless, it was not in the desired position.

                JonBJ 1 Reply Last reply
                0
                • I IknowQT

                  @jsulm
                  @JonB

                  Are you saying you have to manually create the object to use the geometry?
                  I'll test it with the object creation method and tell you the result

                  The question seems to have been understood if the set geometry did not work even during Initialize.
                  However, the question remains as to whether the geometry works when initialized and returns to the original state when setText is executed.

                  One of the things I tested was calling the geometry defined function again after calling setText. Nevertheless, it was not in the desired position.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #7

                  @IknowQT
                  I would not assume anything if you set geometry when a widget is on a layout.

                  Further, even without layouts, I would not rely on geometry returning anything sensible/correct until the widget has been shown.

                  1 Reply Last reply
                  2

                  • Login

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