本文整理汇总了C++中QSizePolicy::hasHeightForWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ QSizePolicy::hasHeightForWidth方法的具体用法?C++ QSizePolicy::hasHeightForWidth怎么用?C++ QSizePolicy::hasHeightForWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSizePolicy
的用法示例。
在下文中一共展示了QSizePolicy::hasHeightForWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: minimumHeightForWidth
/*!
Used to calculate the
Precondition:
\a widget should support either hfw or wfh
If \a heightForWidth is set to false, this function will query the width for height
instead. \a width will then be interpreted as height, \a minh and \a maxh will be interpreted
as minimum width and maximum width.
*/
static qreal minimumHeightForWidth(qreal width, qreal minh, qreal maxh,
const QGraphicsWidget *widget,
bool heightForWidth = true)
{
qreal minimumHeightForWidth = -1;
const QSizePolicy sp = widget->layout() ? widget->layout()->sizePolicy() : widget->sizePolicy();
const bool hasHFW = sp.hasHeightForWidth();
if (hasHFW == heightForWidth) {
minimumHeightForWidth = hasHFW
? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(width, -1)).height()
: widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, width)).width(); //"width" is here height!
} else {
// widthForHeight
const qreal constraint = width;
while (maxh - minh > 0.1) {
qreal middle = minh + (maxh - minh)/2;
// ### really bad, if we are a widget with a layout it will call
// layout->effectiveSizeHint(Qt::MiniumumSize), which again will call
// sizeHint three times because of how the cache works
qreal hfw = hasHFW
? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(middle, -1)).height()
: widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, middle)).width();
if (hfw > constraint) {
minh = middle;
} else if (hfw <= constraint) {
maxh = middle;
}
}
minimumHeightForWidth = maxh;
}
return minimumHeightForWidth;
}
示例2: sizePolicyToString
static QString sizePolicyToString(const QSizePolicy &p)
{
QString rc; {
QTextStream str(&rc);
str << "Control=" << p.controlType() << " expdirs=" << p.expandingDirections()
<< " hasHeightForWidth=" << p.hasHeightForWidth()
<< " H: Policy=" << p.horizontalPolicy()
<< " stretch=" << p.horizontalStretch()
<< " V: Policy=" << p.verticalPolicy()
<< " stretch=" << p.verticalStretch();
}
return rc;
}
示例3: toString
QString LayoutDumper::toString(const QSizePolicy& policy)
{
QString result = QString("(%1, %2)")
.arg(toString(policy.horizontalPolicy()))
.arg(toString(policy.verticalPolicy()));
if (policy.hasHeightForWidth()) {
result += " [hasHeightForWidth]";
}
if (policy.hasWidthForHeight()) {
result += " [hasWidthForHeight]";
}
return result;
}
示例4: _q_boundGeometryToSizeConstraints
static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry,
QRectF *rect, Qt::WindowFrameSection section,
const QSizeF &min, const QSizeF &max,
const QGraphicsWidget *widget)
{
const QRectF proposedRect = *rect;
qreal width = qBound(min.width(), proposedRect.width(), max.width());
qreal height = qBound(min.height(), proposedRect.height(), max.height());
QSizePolicy sp = widget->sizePolicy();
if (const QGraphicsLayout *l = widget->layout()) {
sp = l->sizePolicy();
}
const bool hasHFW = sp.hasHeightForWidth(); // || sp.hasWidthForHeight();
const bool widthChanged = proposedRect.width() < widget->size().width();
const bool heightChanged = proposedRect.height() < widget->size().height();
if (hasHFW) {
if (widthChanged || heightChanged) {
const qreal minh = min.height();
const qreal maxh = max.height();
const qreal proposedHFW = minimumHeightForWidth(width, minh, maxh, widget);
if (proposedHFW > proposedRect.height()) {
QSizeF effectiveSize = closestAcceptableSize(QSizeF(width, height), widget);
width = effectiveSize.width();
height = effectiveSize.height();
}
}
}
switch (section) {
case Qt::LeftSection:
rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(),
qRound(width), startGeometry.height());
break;
case Qt::TopLeftSection:
rect->setRect(startGeometry.right() - qRound(width), startGeometry.bottom() - qRound(height),
qRound(width), qRound(height));
break;
case Qt::TopSection:
rect->setRect(startGeometry.left(), startGeometry.bottom() - qRound(height),
startGeometry.width(), qRound(height));
break;
case Qt::TopRightSection:
rect->setTop(rect->bottom() - qRound(height));
rect->setWidth(qRound(width));
break;
case Qt::RightSection:
rect->setWidth(qRound(width));
break;
case Qt::BottomRightSection:
rect->setWidth(qRound(width));
rect->setHeight(qRound(height));
break;
case Qt::BottomSection:
rect->setHeight(qRound(height));
break;
case Qt::BottomLeftSection:
rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(),
qRound(width), qRound(height));
break;
default:
break;
}
}