当前位置: 首页>>代码示例>>C++>>正文


C++ QAbstractScrollArea::sizeHint方法代码示例

本文整理汇总了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);
}
开发者ID:afester,项目名称:CodeSamples,代码行数:71,代码来源:ScrollAreaLayout.cpp


注:本文中的QAbstractScrollArea::sizeHint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。