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. Resize the "setGeometry" from cpp

Resize the "setGeometry" from cpp

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 736 Views 1 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.
  • M Offline
    M Offline
    mimamrafi
    wrote on last edited by
    #1

    Hai everyone. I want to resize my widget by its geometry. This is the code

    void MainGUI::resizeEvent(QResizeEvent *e)
    {
    	heightsize = e->size().height();
    	float spacing = heightsize/700.0;
    
    	QWidget * channel = new QWidget(this);
    	channelFrame * cF = new channelFrame(channel);
    	cF->setGeometry(10, 40 + ( 75 * spacing), 1115, 35);
    	cF->show();
    }
    

    But it also add the widget, not resizing it. how can I only resize the spacing? Sorry I'm a newbie here

    JonBJ 1 Reply Last reply
    0
    • M mimamrafi

      Hai everyone. I want to resize my widget by its geometry. This is the code

      void MainGUI::resizeEvent(QResizeEvent *e)
      {
      	heightsize = e->size().height();
      	float spacing = heightsize/700.0;
      
      	QWidget * channel = new QWidget(this);
      	channelFrame * cF = new channelFrame(channel);
      	cF->setGeometry(10, 40 + ( 75 * spacing), 1115, 35);
      	cF->show();
      }
      

      But it also add the widget, not resizing it. how can I only resize the spacing? Sorry I'm a newbie here

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

      @mimamrafi
      Hello and welcome.

      But it also add the widget

      You go QWidget * channel = new QWidget(this);, so, yes, that creates and adds a new widget.

      We don't know what your new channelFrame(channel) is.

      I want to resize my widget

      What widget? Some existing one?? The newly created channel one? The newly created channelFrame, which we don't even know whether it is a widget?

      M 1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        @mimamrafi In Qt, if you are manually resizing widgets inside other widgets then you are usually going about your UI the wrong way. Qt has a layout system to arrange contained widgets and this is almost always a set-and-forget problem.

        M 1 Reply Last reply
        3
        • JonBJ JonB

          @mimamrafi
          Hello and welcome.

          But it also add the widget

          You go QWidget * channel = new QWidget(this);, so, yes, that creates and adds a new widget.

          We don't know what your new channelFrame(channel) is.

          I want to resize my widget

          What widget? Some existing one?? The newly created channel one? The newly created channelFrame, which we don't even know whether it is a widget?

          M Offline
          M Offline
          mimamrafi
          wrote on last edited by
          #4

          @JonB the channelFrame is a class that contain many widget.
          ebbfc997-23c8-423c-96f7-27d335997bcc-image.png
          this is the channelframe.ui and I created it repeatedly. Like this
          31eb2e3b-f3ee-4a72-96c1-5ab65a377c1d-image.png

          And I want the channelSpacing more wider when size changed to be like this
          e644eaaf-a573-44e0-bb38-c9a6b56f1406-image.png

          You are right it cannot be solved because I just create new widget again. How to update my widget? How to avoid "new" QWidget? i'm so sorry this is my senior code and I'm newbie in QT

          JonBJ 1 Reply Last reply
          0
          • C ChrisW67

            @mimamrafi In Qt, if you are manually resizing widgets inside other widgets then you are usually going about your UI the wrong way. Qt has a layout system to arrange contained widgets and this is almost always a set-and-forget problem.

            M Offline
            M Offline
            mimamrafi
            wrote on last edited by
            #5

            @ChrisW67 I know there's layout feature, but in my case I have to make it dynamic from cpp

            1 Reply Last reply
            0
            • M mimamrafi

              @JonB the channelFrame is a class that contain many widget.
              ebbfc997-23c8-423c-96f7-27d335997bcc-image.png
              this is the channelframe.ui and I created it repeatedly. Like this
              31eb2e3b-f3ee-4a72-96c1-5ab65a377c1d-image.png

              And I want the channelSpacing more wider when size changed to be like this
              e644eaaf-a573-44e0-bb38-c9a6b56f1406-image.png

              You are right it cannot be solved because I just create new widget again. How to update my widget? How to avoid "new" QWidget? i'm so sorry this is my senior code and I'm newbie in QT

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

              @mimamrafi
              It's difficult to answer your questions. You need a basic understanding of Qt and widgets, which seems to be lacking.

              How to update my widget? How to avoid "new" QWidget?

              Do whatever on your existing widget, don't create a new one. Can't answer any clearer than that.

              I know there's layout feature, but in my case I have to make it dynamic from cpp

              QLayouts can be created from C++ code, not just from e.g. Qt Designer/.ui file. You should be doing all of your desired layout via suitable QLayouts, not setGeomtetry() or any coordinate positioning of widgets, as @ChrisW67 indicated. Your case looks like a QGridLayout.

              1 Reply Last reply
              3
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #7

                @mimamrafi Can you confirm that you want the individual sub-widgets (i.e. the Off, +, - buttons, sliders etc.) to stay exactly the same size and only the space between them to grow if the total available space grows?

                Can you post the UI file that you seem to have for your channelFrame?

                M 1 Reply Last reply
                0
                • C ChrisW67

                  @mimamrafi Can you confirm that you want the individual sub-widgets (i.e. the Off, +, - buttons, sliders etc.) to stay exactly the same size and only the space between them to grow if the total available space grows?

                  Can you post the UI file that you seem to have for your channelFrame?

                  M Offline
                  M Offline
                  mimamrafi
                  wrote on last edited by
                  #8

                  @ChrisW67 I'm using another method, I'm not reccommend this method because its for newbie like me. hehe. So I build one per one of channel frame like this...
                  81e093f8-de90-48b3-bce0-2f4238d2d423-image.png

                  I think it solved but I have to make more codes for this methods

                  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