Results 1 to 3 of 3

Thread: How to keep buttons close to each other (horizontally) in Qt widget?

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default How to keep buttons close to each other (horizontally) in Qt widget?

    Qt Code:
    1. QGridLayout *layout = new QGridLayout ();
    2. centralWidget->setLayout (layout);
    3. layout->addWidget (refresh, 0, 0);
    4. layout->addWidget (zoomIn, 1, 0);
    5. layout->addWidget (zoomOut, 1, 1);
    6. layout->addWidget (panLeft, 2, 0);
    7. layout->addWidget (panRight, 2, 1);
    8. layout->addWidget (panTop, 3, 0);
    9. layout->addWidget (panBottom, 3, 1);
    10. layout->addWidget (findInfo, 4, 0);
    11. layout->addWidget (textEdit, 5, 0);
    12.  
    13. window->setCentralWidget (centralWidget);
    To copy to clipboard, switch view to plain text mode 
    See the screen shot attached.
    qt.jpg

  2. #2
    Join Date
    Jun 2010
    Location
    Pretoria, South Africa
    Posts
    22
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to keep buttons close to each other (horizontally) in Qt widget?

    The big gap you've got is caused by the size of textEdit. You could do two things:

    1. You could make textEdit span two columns using QGridLayout::addWidget(QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0)

    2. You could put all the buttons in a QGridLayout and then add that as the first element in a QVBoxLayout, with textEdit as the second element.

  3. #3
    Join Date
    Feb 2012
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to keep buttons close to each other (horizontally) in Qt widget?

    Yo

    set rowSpan, columnSpan for widgets in QGridLayout::addWidget()

    Qt Code:
    1. Ex:
    2.  
    3. layout->addWidget (panBottom, 3, 1, 1, 1);
    4. layout->addWidget (findInfo, 4, 0, 1, 1);
    5. layout->addWidget (textEdit, 5, 0, 1, 2);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QDialog with Close, Maximize and Context Help Buttons
    By mclark in forum Qt Programming
    Replies: 7
    Last Post: 1st May 2020, 16:53
  2. minimize, maximize and close buttons tooltips
    By kalster in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2011, 07:40
  3. Disable the minimize, maximize,close buttons
    By qtlinuxnewbie in forum Newbie
    Replies: 10
    Last Post: 25th February 2010, 10:18
  4. Replies: 4
    Last Post: 3rd October 2009, 08:19
  5. Replies: 4
    Last Post: 23rd June 2008, 17:11

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.