I have several buttons in a row, but I do not want them to fill the available space. I've tried every manner of SizePolicy, Stretch, Spacers, etc. but the only way I have managed to restrict the width of the buttons is by setting MaximumSize, which unfortunately is not portable (on Mac it clips the button). There must be some easy way of saying "make the button as small as possible without clipping any text or clipping the button itself". Here's some sample code. Any suggestions would be very welcome.

Qt Code:
  1. #include <QApplication>
  2. #include <QtGui>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication app(argc, argv);
  7.  
  8. QFrame *frame = new QFrame();
  9. frame->setFrameShape(QFrame::Box);
  10. frame->setFrameShadow(QFrame::Plain);
  11.  
  12. QPushButton *left = new QPushButton("<", frame);
  13. QPushButton *middle = new QPushButton("LongString", frame);
  14. QPushButton *right = new QPushButton(">", frame);
  15.  
  16. QGridLayout *row_layout = new QGridLayout;
  17. row_layout->addWidget(left,0,0);
  18. row_layout->addWidget(middle,0,1);
  19. row_layout->addWidget(right,0,2);
  20.  
  21. row_layout->setColumnStretch(0,5); // has no effect
  22. left->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); // has no effect
  23.  
  24. frame->setLayout(row_layout);
  25. frame->show();
  26.  
  27. return app.exec();
  28. }
To copy to clipboard, switch view to plain text mode