本文整理汇总了C++中QPushButton::fontMetrics方法的典型用法代码示例。如果您正苦于以下问题:C++ QPushButton::fontMetrics方法的具体用法?C++ QPushButton::fontMetrics怎么用?C++ QPushButton::fontMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPushButton
的用法示例。
在下文中一共展示了QPushButton::fontMetrics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QPushButton
QPushButton *minimumSizeButton(const std::string &text, QWidget *parent)
{
QPushButton *button = new QPushButton(text.c_str(), parent);
QSize textSize = button->fontMetrics().size(Qt::TextShowMnemonic, button->text());
QStyleOptionButton opt;
opt.initFrom(button);
opt.rect.setSize(textSize);
button->setMinimumSize(button->style()->sizeFromContents(QStyle::CT_PushButton, &opt, textSize, button));
button->setMaximumSize(button->style()->sizeFromContents(QStyle::CT_PushButton, &opt, textSize, button));
return button;
}
示例2: init
//Construct the base GUI, and connect the signals
void FileLineEdit::init(QString title, QFileDialog::FileMode mode)
{
//Layout
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
//Line edit
_line = new QLineEdit();
layout->addWidget(_line);
CONNECT(_line, SIGNAL(textChanged(QString)), this, SLOT(updateFileName(QString)));
//Button
QPushButton *button = new QPushButton(tr("Select..."));
//Reduce the button size so that it's not higher than the line edit, and not much larger than its text
button->setMaximumHeight(_line->size().height()-5);
button->setMaximumWidth(button->fontMetrics().boundingRect(button->text()).width()+15);
layout->addWidget(button);
CONNECT(button, SIGNAL(clicked()), this, SLOT(clicked()));
//Create the file dialog and set its mode
_fileDialog = new QFileDialog(this,title,QDir::homePath());
_fileDialog->setFileMode(mode);
}