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 issues
Qt 6.11 is out! See what's new in the release blog

QGroupBox issues

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

    Okay, I'm trying to group up some labels and line edits in a stacked widget, but I'm having trouble understanding how to do it.
    Currently, I have this code:

        int z=0;
        for (int i=0; i<3; i++)
        {
            QVBoxLayout *vertical=new QVBoxLayout;
            QWidget *page = new QWidget;
            for (int j = 0; j < 5; j++) {
                //QGroupBox *grp=new QGroupBox();
                QLabel *lbl=new QLabel("Something("+QString::number(z)+")");
                QLineEdit *txt=new QLineEdit();
                vertical->addWidget(lbl);
                vertical->addWidget(txt);
                z++;
            }
            page->setLayout(vertical);
            ui->stck->insertWidget(i, page);
        }
            ui->stck->setCurrentIndex(0);
    

    This code looks like:
    Screenshot_1.png
    What I would like to do is:
    Screenshot_2.png
    The purpose of this is I'm making a quiz maker for my school project and this is how I'm thinking of grouping questions with answers, if anyone's got a better idea, let me know.

    JonBJ 1 Reply Last reply
    0
    • I Inzinejkr

      Okay, I'm trying to group up some labels and line edits in a stacked widget, but I'm having trouble understanding how to do it.
      Currently, I have this code:

          int z=0;
          for (int i=0; i<3; i++)
          {
              QVBoxLayout *vertical=new QVBoxLayout;
              QWidget *page = new QWidget;
              for (int j = 0; j < 5; j++) {
                  //QGroupBox *grp=new QGroupBox();
                  QLabel *lbl=new QLabel("Something("+QString::number(z)+")");
                  QLineEdit *txt=new QLineEdit();
                  vertical->addWidget(lbl);
                  vertical->addWidget(txt);
                  z++;
              }
              page->setLayout(vertical);
              ui->stck->insertWidget(i, page);
          }
              ui->stck->setCurrentIndex(0);
      

      This code looks like:
      Screenshot_1.png
      What I would like to do is:
      Screenshot_2.png
      The purpose of this is I'm making a quiz maker for my school project and this is how I'm thinking of grouping questions with answers, if anyone's got a better idea, let me know.

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

      @Inzinejkr

              for (int j = 0; j < 5; j++) {
                  QGroupBox *grp=new QGroupBox();
                  QVBoxLayout *grpLayout = new QVBoxLayout();
                  QLabel *lbl=new QLabel("Something("+QString::number(z)+")");
                  QLineEdit *txt=new QLineEdit();
                  grpLayout->addWidget(lbl);
                  grpLayout->addWidget(txt);
                  grp->setLayout(grpLayout);
                  vertical->addWidget(grp);
                  z++;
              }
      

      Cf. https://doc.qt.io/qt-5/qgroupbox.html#details sample code box.

      1 Reply Last reply
      2
      • I Offline
        I Offline
        Inzinejkr
        wrote on last edited by
        #3

        @JonB
        Thank you so much.

        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