查看完整版本: [-- Qt FlowLayout 升级版 --]

QTCN开发网 -> Qt代码秀 -> Qt FlowLayout 升级版 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

305750665 2019-05-30 20:24

Qt FlowLayout 升级版

效果图
[attachment=20397]



核心代码
  1. if(itemList[i]->sizeHint().height() == 0) continue;
            int nextX = x + itemList[i]->sizeHint().width() + spaceX;
            int nextY = y;
            if(x > effectiveRect.x()){
                nextX = x;
                nextY = y + itemList[i]->sizeHint().height() + spaceY;

                if(nextY - spaceY >= preY + lineHeight && lineHeight > 0 && lineWidth > 0){
                    x = x + lineWidth + spaceX;
                    y = preY;
                    nextX = x;
                    nextY = y + itemList[i]->sizeHint().height() + spaceY;
                    lineWidth = 0;
                }
                lineWidth = qMax(lineWidth, itemList[i]->sizeHint().width());
            }

            if (nextX + itemList[i]->sizeHint().width() > effectiveRect.right() && lineHeight > 0) {
                x = effectiveRect.x();
                y = preY + lineHeight + spaceY;
                preY = y;
                nextX = x + itemList[i]->sizeHint().width() + spaceX;
                nextY = y;
                lineHeight = 0;
                lineWidth = 0;
            }

            if (!testOnly)
            {
                itemList[i]->setGeometry(QRect(QPoint(x, y), itemList[i]->sizeHint()));
            }
            
            lineHeight = qMax(lineHeight, itemList[i]->sizeHint().height());
            x = nextX;
            y = nextY;
        }


更多精彩内容:欢迎访问雨田哥博客


dinjay 2019-09-12 15:23
    


查看完整版本: [-- Qt FlowLayout 升级版 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled