Results 1 to 4 of 4

Thread: How to do that?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    4

    Default How to do that?

    Here is sample:


    So I would like to do something similar. As You can see there is some QGroupBox with 3 horizontal QLayouts in it. These layouts contains some widgets. And here appears my problem. How to put these layouts inside this groupbox. Setting QGroupBox as a parent doesn't seem to work, because debug functions say that QGroupBox already have a layout. When I do that in a "traditional way" (creating QLayout with QGroupBox as a parent) these widgets don't show in program.
    Please help.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: How to do that?

    It simple release with Designer !
    Where is your problem ?
    I attch screenshot that i release in designer and also give you code that was generated form ui file...

    Qt Code:
    1. Form1Layout = new QGridLayout( this, 1, 1, 11, 6, "Form1Layout");
    2.  
    3. groupBox1 = new QGroupBox( this, "groupBox1" );
    4. groupBox1->setColumnLayout(0, Qt::Vertical );
    5. groupBox1->layout()->setSpacing( 6 );
    6. groupBox1->layout()->setMargin( 11 );
    7. groupBox1Layout = new QGridLayout( groupBox1->layout() );
    8. groupBox1Layout->setAlignment( Qt::AlignTop );
    9.  
    10. layout1 = new QHBoxLayout( 0, 0, 6, "layout1");
    11.  
    12. checkBox1 = new QCheckBox( groupBox1, "checkBox1" );
    13. layout1->addWidget( checkBox1 );
    14.  
    15. textLabel1 = new QLabel( groupBox1, "textLabel1" );
    16. layout1->addWidget( textLabel1 );
    17.  
    18. spinBox1 = new QSpinBox( groupBox1, "spinBox1" );
    19. layout1->addWidget( spinBox1 );
    20.  
    21. groupBox1Layout->addLayout( layout1, 0, 0 );
    22.  
    23. layout2 = new QHBoxLayout( 0, 0, 6, "layout2");
    24.  
    25. checkBox1_2 = new QCheckBox( groupBox1, "checkBox1_2" );
    26. layout2->addWidget( checkBox1_2 );
    27.  
    28. textLabel1_2 = new QLabel( groupBox1, "textLabel1_2" );
    29. layout2->addWidget( textLabel1_2 );
    30.  
    31. spinBox1_2 = new QSpinBox( groupBox1, "spinBox1_2" );
    32. layout2->addWidget( spinBox1_2 );
    33.  
    34. groupBox1Layout->addLayout( layout2, 1, 0 );
    35.  
    36. layout3 = new QHBoxLayout( 0, 0, 6, "layout3");
    37.  
    38. checkBox1_3 = new QCheckBox( groupBox1, "checkBox1_3" );
    39. layout3->addWidget( checkBox1_3 );
    40.  
    41. textLabel1_2_2 = new QLabel( groupBox1, "textLabel1_2_2" );
    42. layout3->addWidget( textLabel1_2_2 );
    43.  
    44. spinBox1_3 = new QSpinBox( groupBox1, "spinBox1_3" );
    45. layout3->addWidget( spinBox1_3 );
    46.  
    47. groupBox1Layout->addLayout( layout3, 2, 0 );
    48.  
    49. Form1Layout->addWidget( groupBox1, 0, 0 );
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    • File Type: png 3.png (8.0 KB, 15 views)
    a life without programming is like an empty bottle

  3. The following user says thank you to zlatko for this useful post:

    conexion2000 (16th May 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to do that?

    Quote Originally Posted by conexion2000
    Here is sample:


    So I would like to do something similar. As You can see there is some QGroupBox with 3 horizontal QLayouts in it. These layouts contains some widgets. And here appears my problem. How to put these layouts inside this groupbox. Setting QGroupBox as a parent doesn't seem to work, because debug functions say that QGroupBox already have a layout. When I do that in a "traditional way" (creating QLayout with QGroupBox as a parent) these widgets don't show in program.
    Please help.
    You must use QWidget::setLayout.

    Qt Code:
    1. lay1->addWidget(wgt1_1);
    2. ...
    3. lay1->addWidget(wgt1_N);
    4.  
    5. ..........
    6.  
    7. layN->addWidget(wgtN_1);
    8. ...
    9. layN->addWidget(wgtN_N);
    10.  
    11. v->addLayout(lay1);
    12. ...
    13. v->addLayout(layN);
    14.  
    15. grpBox->setLayout(v)
    To copy to clipboard, switch view to plain text mode 

    where wgtX_X are widget to add and grpBox are your QGroupBox.
    A camel can go 14 days without drink,
    I can't!!!

  5. #4
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    4

    Default Re: How to do that?

    Problem solved thanks to your code zlatko.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.