Results 1 to 2 of 2

Thread: How to Remove Spacing between widgets added to QHBoxLayout programmetically

  1. #1
    Join Date
    Feb 2014
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to Remove Spacing between widgets added to QHBoxLayout programmetically

    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 

  2. #2
    Join Date
    Feb 2014
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to Remove Spacing between widgets added to QHBoxLayout programmetically

    I found it. Its the border size.
    When I edit borders in the css stylesheets, I am able to control the spacing shown in the image.
    http://qt-project.org/doc/qt-4.8/sty...html#box-model

Similar Threads

  1. QHBoxLayout widget spacing
    By K4ELO in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2013, 13:47
  2. remove QVBoxLayout content in QHBoxLayout
    By jackajack01 in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2012, 11:53
  3. How to remove Space Between 2 QHBoxLayout Widget
    By jaya in forum Qt Programming
    Replies: 3
    Last Post: 6th October 2010, 22:57
  4. How to remove widget added in runtime?
    By jiveaxe in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2007, 10:13
  5. Spacing widgets and actions in a toolbar
    By indifference in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2007, 22:59

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.