本文整理汇总了C++中QAbstractScrollArea::sizeHint方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractScrollArea::sizeHint方法的具体用法?C++ QAbstractScrollArea::sizeHint怎么用?C++ QAbstractScrollArea::sizeHint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractScrollArea
的用法示例。
在下文中一共展示了QAbstractScrollArea::sizeHint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setGeometry
void ScrollAreaLayout::setGeometry ( const QRect & r ) {
QAbstractScrollArea* theChild = dynamic_cast<QAbstractScrollArea*>(theItem->widget());
//qDebug() << "--------------------------------------";
// qDebug() << " Layout geometry:" << r;
//qDebug() << " Scroll bar width: " << theChild->verticalScrollBar()->width();
// get the widget which is scrolled by the scrollarea
//QWidget* wdg = theChild->widget();
// qDebug() << "Widget sizeHint():" << wdg->objectName() << " - "<< wdg->sizeHint();
//qDebug() << "Widget size():" << wdg->objectName() << " - "<< wdg->size();
// int fh = theChild->fontMetrics().height();
//qDebug() << "Scroll area max size:" << QSize(36 * fh, 24 * fh);
int wid = theChild->sizeHint().width(); // frame width is considered!
int h = theChild->sizeHint().height(); // frame height is considered!
int xpos = 0;
int ypos = 0;
if (r.width() < wid && r.height() < h) {
// both scrollbars required
wid = r.width();
h = r.height();
} else if (r.width() < wid) {
// only horizontal scroll bar required
h += theChild->horizontalScrollBar()->sizeHint().height();
wid = r.width();
// the new y position is based on the extended height (including scroll bars)
// this leads to a lesser smoothly transition from no scroll bars to scroll bars,
// but avoids an asymmetry once the scroll bars are shown.
ypos = (r.height() - h) / 2;
if (r.height() < h) { // again both required
xpos = 0;
ypos = 0;
h = r.height();
}
} else if (r.height() < h) {
// only vertical scroll bar required
wid += theChild->verticalScrollBar()->sizeHint().width();
h = r.height();
// the new x position is based on the extended width (including scroll bars)
// this leads to a lesser smoothly transition from no scroll bars to scroll bars,
// but avoids an asymmetry once the scroll bars are shown.
xpos = (r.width() - wid) / 2;
if (r.width() < wid) { // again both required
xpos = 0;
ypos = 0;
wid = r.width();
}
} else {
xpos = (r.width() - wid) / 2;
ypos = (r.height() - h) / 2;
}
int frameWidth = 0; // !!!!
QRect newRect = QRect(xpos, ypos, wid + frameWidth, h + frameWidth);
//qDebug() << " Child geometry:" << newRect;
theChild->setGeometry(newRect);
}