本文整理汇总了C++中QToolButton::width方法的典型用法代码示例。如果您正苦于以下问题:C++ QToolButton::width方法的具体用法?C++ QToolButton::width怎么用?C++ QToolButton::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QToolButton
的用法示例。
在下文中一共展示了QToolButton::width方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateItemWidgets
void NodeTypesDelegate::updateItemWidgets(const QList< QWidget* > widgets, const QStyleOptionViewItem& option, const QPersistentModelIndex& index) const
{
// widgets:
// ColorButton | Title | ID
if (!index.isValid()) {
return;
}
Q_ASSERT(widgets.size() == 4);
KColorButton *colorButton = qobject_cast<KColorButton*>(widgets.at(0));
QLineEdit *title = qobject_cast<QLineEdit*>(widgets.at(1));
QLabel *id = qobject_cast<QLabel*>(widgets.at(2));
QToolButton *propertiesButton = qobject_cast<QToolButton*>(widgets.at(3));
Q_ASSERT(title);
Q_ASSERT(colorButton);
Q_ASSERT(id);
Q_ASSERT(propertiesButton);
colorButton->setColor(index.data(NodeTypeModel::ColorRole).value<QColor>());
title->setText(index.data(NodeTypeModel::TitleRole).toString());
id->setText(index.data(NodeTypeModel::IdRole).toString());
QRect outerRect(0, 0, option.rect.width(), option.rect.height());
QRect contentRect = outerRect.adjusted(m_hPadding, m_vPadding, -m_hPadding, -m_vPadding);
int colorButtonLeftMargin = contentRect.left();
int colorButtonTopMargin = (outerRect.height() - colorButton->height()) / 2;
colorButton->move(colorButtonLeftMargin, colorButtonTopMargin);
int titleLeftMargin = colorButtonLeftMargin + colorButton->width() + 10;
int titleTopMargin = (outerRect.height() - title->height()) / 2;
title->move(titleLeftMargin, titleTopMargin);
// construct remaining from right to left
int propertiesLeftMargin = contentRect.right() - propertiesButton->width() - m_hPadding;
int propertiesTopMargin = (outerRect.height() - propertiesButton->height()) / 2;
propertiesButton->move(propertiesLeftMargin, propertiesTopMargin);
int idLeftMargin = propertiesLeftMargin - id->width() - 10;
int idTopMargin = (outerRect.height() - id->height()) / 2;
id->move(idLeftMargin, idTopMargin);
// title gets remaining space
title->setFixedWidth(qMax(0, idLeftMargin - titleLeftMargin - 10));
}
示例2: visualRect
/* FIXME make this less of a hack. */
QRect TestCalendarWidget::visualRect(QString const &item) const
{
TestWidgetsLog() << item << "my geometry is" << geometry();
QRect ret;
QAbstractItemView *view = q->findChild<QAbstractItemView*>();
QtUiTest::ListWidget *calendarView
= qtuitest_cast<QtUiTest::ListWidget*>(view);
if (!calendarView) {
return ret;
}
ret = calendarView->visualRect(item);
if (!ret.isNull()) {
ret.moveTopLeft( q->mapFromGlobal( view->mapToGlobal(ret.topLeft()) ) );
TestWidgetsLog() << item << "is a visible day at" << ret;
return ret;
}
QToolButton *yearButton = 0;
QToolButton *monthButton = 0;
QSpinBox *yearSpin = q->findChild<QSpinBox*>();
QMenu *monthMenu = 0;
QList<QToolButton*> blist = q->findChildren<QToolButton*>();
foreach(QToolButton *b, blist) {
if (!monthButton && (monthMenu = b->menu())) {
monthButton = b;
}
if (!b->menu()) {
yearButton = b;
}
}
TestWidgetsLog() << "monthButton" << monthButton << "yearButton" << yearButton;
TestWidgetsLog() << "item" << item << "monthMenu" << monthMenu;
if (yearButton && yearButton->isVisible() && yearButton->text() == item) {
QPoint p = q->mapFromGlobal( yearButton->mapToGlobal(QPoint(yearButton->width()+5, yearButton->height()/2)) );
ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
TestWidgetsLog() << "click near yearbutton";
} else if (yearSpin && yearSpin->isVisible() && yearSpin->value() == item.toInt()) {
TestWidgetsLog() << "confirm spinbox";
QPoint p = q->mapFromGlobal( yearSpin->mapToGlobal(QPoint(yearSpin->width()+5, yearSpin->height()/2)) );
ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
} else if (monthButton && monthButton->isVisible() && monthButton->text() == item) {
QPoint p = q->mapFromGlobal( monthButton->mapToGlobal(QPoint(-5, monthButton->height()/2)) );
ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
TestWidgetsLog() << "click near monthbutton";
} else if (monthMenu && monthMenu->isVisible()
&& qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)
&& qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)->list().contains(item)) {
ret = qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)->visualRect(item);
ret.moveTopLeft( q->mapFromGlobal( monthMenu->mapToGlobal(ret.topLeft()) ) );
TestWidgetsLog() << "click on monthmenu";
} else {
do {
QStringList items = list();
if (items.contains(item)) {
ret = QRect(-1, -1, 1, 1);
ret.moveTopLeft( q->mapFromGlobal(QPoint(-1,-1)) );
break;
}
foreach (QString s, items) {
if (!s.startsWith(GetListRegExp)) continue;
QRegExp re(s.mid(GetListRegExp.length()));
if (re.exactMatch(item)) {
ret = QRect(-1, -1, 1, 1);
ret.moveTopLeft( q->mapFromGlobal(QPoint(-1,-1)) );
break;
}
}
if (!ret.isNull()) break;
} while(0);
}
TestWidgetsLog() << "returning rect" << ret;
return ret;
}