That's because you set the button as the parent of the label. What you want doesn't work like you tried it.

Here's a better solution (don't copy and past, check it first)
Qt Code:
  1. QWidget *myContainerWidget = new QWidget;
  2. QGridLayout *myContainingLayout = new QGridLayout;
  3.  
  4. QLabel *myLabel = new QLabel;
  5. myLabel->setText("my label");
  6.  
  7. QPushButton *myButton = new QPushButton;
  8. myButton->setText("my button");
  9.  
  10. myContainingLayout->addWidget(myLabel);
  11. myContainingLayout->addWidget(myButton);
  12.  
  13. myContainerWidget->setLayout(myContainingLayout);
  14.  
  15. myContainerWidget->show();
To copy to clipboard, switch view to plain text mode