clipboard.png

When using the following code, how can I get rid of the spacing between buttons added to the QHBoxLayout, which is inturn added to QFrame?
Usage of "layout->setSpacing(0)" reduced the space between the buttons, but did not remove the space completely.

Attached is screenshot after executing the below code.

Thanks a lot for your help.

Qt Code:
  1. #include <QtGui>
  2.  
  3. int main(int argc,char** argv)
  4. {
  5. QApplication app(argc,argv);
  6.  
  7. QMainWindow* window = new QMainWindow();
  8. QFrame* centralWidget = new QFrame();
  9. QHBoxLayout* layout = new QHBoxLayout();
  10.  
  11. window->setCentralWidget(centralWidget);
  12. centralWidget->setLayout(layout);
  13.  
  14. layout->addWidget(new QPushButton("Button 1"));
  15. layout->addWidget(new QPushButton("Button 2"));
  16.  
  17. window->setWindowTitle("Spacing in HBoxLayout");
  18.  
  19. layout->addStretch(0);
  20. layout->setContentsMargins(0,0,0,0);
  21. layout->setSpacing(0);
  22.  
  23. window->show();
  24. return app.exec();
  25. }
To copy to clipboard, switch view to plain text mode