你可以使用 QLayout 的 count() 函数来获取 QLayoutItem 指针内的个体数量。例如:

QLayout* layout = new QVBoxLayout;
int itemCount = layout->count();

注意,count() 函数返回的是 QLayoutItem 指针内的个体数量,而不是具体的 widget 数量。如果你想获取具体的 widget 数量,你可以使用 QLayout::widget() 函数来遍历 QLayoutItem 指针并计数。例如:

QLayout* layout = new QVBoxLayout;

int widgetCount = 0;
for (int i = 0; i < layout->count(); ++i) {
    QLayoutItem* item = layout->itemAt(i);
    QWidget* widget = item->widget();
    if (widget) {
        ++widgetCount;
    }
}

这样你就可以得到 QLayoutItem 指针内的具体 widget 数量。

Qt 获取 QLayoutItem 指针内内容数量

原文地址: https://www.cveoy.top/t/topic/qtSC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录