• 3574阅读
  • 1回复

Qt FlowLayout 升级版 [复制链接]

上一主题 下一主题
离线305750665
 

只看楼主 正序阅读 楼主  发表于: 2019-05-30
效果图




核心代码
  1. if(itemList[i]->sizeHint().height() == 0) continue;
  2.         int nextX = x + itemList[i]->sizeHint().width() + spaceX;
  3.         int nextY = y;
  4.         if(x > effectiveRect.x()){
  5.             nextX = x;
  6.             nextY = y + itemList[i]->sizeHint().height() + spaceY;
  7.             if(nextY - spaceY >= preY + lineHeight && lineHeight > 0 && lineWidth > 0){
  8.                 x = x + lineWidth + spaceX;
  9.                 y = preY;
  10.                 nextX = x;
  11.                 nextY = y + itemList[i]->sizeHint().height() + spaceY;
  12.                 lineWidth = 0;
  13.             }
  14.             lineWidth = qMax(lineWidth, itemList[i]->sizeHint().width());
  15.         }
  16.         if (nextX + itemList[i]->sizeHint().width() > effectiveRect.right() && lineHeight > 0) {
  17.             x = effectiveRect.x();
  18.             y = preY + lineHeight + spaceY;
  19.             preY = y;
  20.             nextX = x + itemList[i]->sizeHint().width() + spaceX;
  21.             nextY = y;
  22.             lineHeight = 0;
  23.             lineWidth = 0;
  24.         }
  25.         if (!testOnly)
  26.         {
  27.             itemList[i]->setGeometry(QRect(QPoint(x, y), itemList[i]->sizeHint()));
  28.         }
  29.         
  30.         lineHeight = qMax(lineHeight, itemList[i]->sizeHint().height());
  31.         x = nextX;
  32.         y = nextY;
  33.     }


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

雨田哥: 群号:853086607
QQ: 3246214072

刘典武-feiyangqingyun:专业各种自定义控件编写+UI定制+输入法定制+视频监控+工业控制+仪器仪表+嵌入式linux+各种串口网络通信,童叟无欺,量大从优,欢迎咨询购买定制!QQ:517216493
离线dinjay

只看该作者 1楼 发表于: 2019-09-12
    
快速回复
限100 字节
 
上一个 下一个