305750665 |
2019-05-30 20:24 |
Qt FlowLayout 升级版
效果图 [attachment=20397]
核心代码
- 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; }
更多精彩内容:欢迎访问雨田哥博客
|
|