Originally Posted by
Ishmael
There must be some easy way of saying "make the button as small as possible without clipping any text or clipping the button itself".
Try:
#include <QApplication>
#include <QtGui>
int main(int argc, char *argv[])
{
frame
->setFrameShape
(QFrame::Box);
frame
->setFrameShadow
(QFrame::Plain);
row_layout->addWidget(left ,0, 0, Qt::AlignLeft);
row_layout->addWidget(middle,0, 1, Qt::AlignCenter);
row_layout->addWidget(right ,0, 2, Qt::AlignRight);
frame->setLayout(row_layout);
frame->show();
return app.exec();
}
#include <QApplication>
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFrame *frame = new QFrame();
frame->setFrameShape(QFrame::Box);
frame->setFrameShadow(QFrame::Plain);
QPushButton *left = new QPushButton("<", frame);
QPushButton *middle = new QPushButton("LongString", frame);
QPushButton *right = new QPushButton(">", frame);
QGridLayout *row_layout = new QGridLayout;
row_layout->addWidget(left ,0, 0, Qt::AlignLeft);
row_layout->addWidget(middle,0, 1, Qt::AlignCenter);
row_layout->addWidget(right ,0, 2, Qt::AlignRight);
frame->setLayout(row_layout);
frame->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
or, if you do not want the current style’s minimum width for push buttons (which is why the left and right buttons don’t shrink in the above) enforced:
#include <QApplication>
#include <QtGui>
int main(int argc, char *argv[])
{
frame
->setFrameShape
(QFrame::Box);
frame
->setFrameShadow
(QFrame::Plain);
left ->setToolButtonStyle(Qt::ToolButtonTextOnly);
middle->setToolButtonStyle(Qt::ToolButtonTextOnly);
right ->setToolButtonStyle(Qt::ToolButtonTextOnly);
left ->setText("<");
middle->setText("LongString");
right ->setText(">");
row_layout->addWidget(left , 0, 0, Qt::AlignLeft);
row_layout->addWidget(middle, 0, 1, Qt::AlignCenter);
row_layout->addWidget(right , 0, 2, Qt::AlignRight);
frame->setLayout(row_layout);
frame->show();
return app.exec();
}
#include <QApplication>
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFrame *frame = new QFrame();
frame->setFrameShape(QFrame::Box);
frame->setFrameShadow(QFrame::Plain);
QToolButton *left = new QToolButton(frame);
QToolButton *middle = new QToolButton(frame);
QToolButton *right = new QToolButton(frame);
left ->setToolButtonStyle(Qt::ToolButtonTextOnly);
middle->setToolButtonStyle(Qt::ToolButtonTextOnly);
right ->setToolButtonStyle(Qt::ToolButtonTextOnly);
left ->setText("<");
middle->setText("LongString");
right ->setText(">");
QGridLayout *row_layout = new QGridLayout;
row_layout->addWidget(left , 0, 0, Qt::AlignLeft);
row_layout->addWidget(middle, 0, 1, Qt::AlignCenter);
row_layout->addWidget(right , 0, 2, Qt::AlignRight);
frame->setLayout(row_layout);
frame->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks