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. QGroupBox and positioning a button on a QGroupBox
Forum Updated to NodeBB v4.3 + New Features

QGroupBox and positioning a button on a QGroupBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 377 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
    stretchthebits
    wrote on last edited by
    #1

    Hello all,
    I am creating a QGroupBox on my QMainWindow window.

    QGroupBox		*GROUPBOXChemicalEquation;
    GROUPBOXChemicalEquation=new QGroupBox(this);
    GROUPBOXChemicalEquation->setGeometry(X, Y, width, height);
    GROUPBOXChemicalEquation->setTitle("Chemical Equation");
    
    

    So, that looks fine and good.
    Then I want to place some controls on it. Let’s say, I want to put this button:

    BUTTONCopyEnergy3=new QPushButton(“Copy”, GROUPBOXChemicalEquation); <====notice the  GROUPBOXChemicalEquation
    BUTTONCopyEnergy3->setGeometry(0, 0, BUTTONCopyEnergy3PosSize[2], BUTTONCopyEnergy3PosSize[3]);
    

    THE PROBLEM:
    The problem is the position of the button. It positions the button over the header text: Chemical EquationzzzBug.png

    JonBJ 1 Reply Last reply
    0
    • S stretchthebits

      Hello all,
      I am creating a QGroupBox on my QMainWindow window.

      QGroupBox		*GROUPBOXChemicalEquation;
      GROUPBOXChemicalEquation=new QGroupBox(this);
      GROUPBOXChemicalEquation->setGeometry(X, Y, width, height);
      GROUPBOXChemicalEquation->setTitle("Chemical Equation");
      
      

      So, that looks fine and good.
      Then I want to place some controls on it. Let’s say, I want to put this button:

      BUTTONCopyEnergy3=new QPushButton(“Copy”, GROUPBOXChemicalEquation); <====notice the  GROUPBOXChemicalEquation
      BUTTONCopyEnergy3->setGeometry(0, 0, BUTTONCopyEnergy3PosSize[2], BUTTONCopyEnergy3PosSize[3]);
      

      THE PROBLEM:
      The problem is the position of the button. It positions the button over the header text: Chemical EquationzzzBug.png

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

      @stretchthebits
      As ever, you are supposed to place a layout and not use absolute size/positioning to place widgets on boxes. Have you looked at the basic example at https://doc.qt.io/qt-5/qgroupbox.html#details ?

      S 1 Reply Last reply
      2
      • JonBJ JonB

        @stretchthebits
        As ever, you are supposed to place a layout and not use absolute size/positioning to place widgets on boxes. Have you looked at the basic example at https://doc.qt.io/qt-5/qgroupbox.html#details ?

        S Offline
        S Offline
        stretchthebits
        wrote on last edited by
        #3

        @JonB That seems to be fine for a simple arrangement but I am not sure how to have the look as can been in the screenshot.
        And why not calculate and position controls ourselves?

        Christian EhrlicherC 1 Reply Last reply
        0
        • S stretchthebits

          @JonB That seems to be fine for a simple arrangement but I am not sure how to have the look as can been in the screenshot.
          And why not calculate and position controls ourselves?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @stretchthebits said in QGroupBox and positioning a button on a QGroupBox:

          And why not calculate and position controls ourselves?

          You can if you want to do all the calculations by yourself. But this is not trivial and what's the layout manager is for.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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