Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt';这是什么样的工作?_C++_Qt - Fatal编程技术网

C++ Qt';这是什么样的工作?

C++ Qt';这是什么样的工作?,c++,qt,C++,Qt,我正在尝试修改该文件。然而,在阅读代码时,我不理解以下几行是如何工作的: item->setGeometry(QRect(item->geometry().x(), item->geometry().y(), rect.width(), item->sizeHint().height()); southHeight += item->geometry().height() + spacing(); item->setGeometry(QRect(rect.x(),

我正在尝试修改该文件。然而,在阅读代码时,我不理解以下几行是如何工作的:

item->setGeometry(QRect(item->geometry().x(),
    item->geometry().y(), rect.width(),
    item->sizeHint().height());

southHeight += item->geometry().height() + spacing();

item->setGeometry(QRect(rect.x(),
     rect.y() + rect.height() - southHeight + spacing(),
     item->geometry().width(),
     item->geometry().height()));
为什么setGeometry要调用两次?另外,item->geometry()的设置是什么/如何设置的(我知道它可能是由QLayout::setGeometry(rect)设置的,但是查看QLayout的源代码,该函数所做的就是将rect分配给一个内部指针)

全部功能是:

void BorderLayout::setGeometry(const QRect &rect)
 {
     ItemWrapper *center = 0;
     int eastWidth = 0;
     int westWidth = 0;
     int northHeight = 0;
     int southHeight = 0;
     int centerHeight = 0;
     int i;

     QLayout::setGeometry(rect);

     for (i = 0; i < list.size(); ++i) {
         ItemWrapper *wrapper = list.at(i);
         QLayoutItem *item = wrapper->item;
         Position position = wrapper->position;

         if (position == North) {
             item->setGeometry(QRect(rect.x(), northHeight, rect.width(),
                                     item->sizeHint().height()));

             northHeight += item->geometry().height() + spacing();
         } else if (position == South) {
             item->setGeometry(QRect(item->geometry().x(),
                                     item->geometry().y(), rect.width(),
                                     item->sizeHint().height()));

             southHeight += item->geometry().height() + spacing();

             item->setGeometry(QRect(rect.x(),
                               rect.y() + rect.height() - southHeight + spacing(),
                               item->geometry().width(),
                               item->geometry().height()));
         } else if (position == Center) {
             center = wrapper;
         }
     }

     centerHeight = rect.height() - northHeight - southHeight;

     for (i = 0; i item;
         Position position = wrapper->position;

         if (position == West) {
             item->setGeometry(QRect(rect.x() + westWidth, northHeight,
                                     item->sizeHint().width(), centerHeight));

             westWidth += item->geometry().width() + spacing();
         } else if (position == East) {
             item->setGeometry(QRect(item->geometry().x(), item->geometry().y(),
                                     item->sizeHint().width(), centerHeight));

             eastWidth += item->geometry().width() + spacing();

             item->setGeometry(QRect(
                               rect.x() + rect.width() - eastWidth + spacing(),
                               northHeight, item->geometry().width(),
                               item->geometry().height()));
         }
     }

     if (center)
         center->item->setGeometry(QRect(westWidth, northHeight,
                                         rect.width() - eastWidth - westWidth,
                                         centerHeight));
 }
void BorderLayout::setGeometry(const QRect&rect)
{
ItemWrapper*中心=0;
int东宽=0;
int-westWidth=0;
int northHeight=0;
int southHeight=0;
int中心高度=0;
int i;
QLayout::setGeometry(rect);
对于(i=0;i项目;
位置=包装器->位置;
如果(位置==北){
item->setGeometry(QRect(rect.x()、northHeight、rect.width()、,
项目->大小提示().height());
northHeight+=项目->几何体().高度()+间距();
}否则如果(位置==南){
项目->设置几何体(QRect(项目->几何体().x(),
项目->几何体().y(),矩形宽度(),
项目->大小提示().height());
southHeight+=项目->几何体().高度()+间距();
item->setGeometry(QRect(rect.x()),
矩形y()+矩形高度()-南部高度+间距(),
项目->几何体().width(),
项目->几何体().高度());
}否则如果(位置==中心){
中心=包装器;
}
}
中心高度=垂直高度()-北高-南高;
对于(i=0;i项;
位置=包装器->位置;
如果(位置==西){
item->setGeometry(QRect(rect.x()+westWidth、northHeight、,
项目->尺寸中心().width(),中心高度);
westWidth+=项目->几何体().宽度()+间距();
}否则如果(位置==东){
项目->设置几何体(QRect(项目->几何体().x(),项目->几何体().y(),
项目->尺寸中心().width(),中心高度);
eastWidth+=项目->几何体().width()+间距();
项目->设置几何体(QRect)(
矩形x()+矩形宽度()-eastWidth+间距(),
northHeight,item->geometry().width(),
项目->几何体().高度());
}
}
如果(中)
居中->项目->设置几何图形(QRect(西宽、北高、,
矩形宽度()-eastWidth-westWidth,
中心高度);
}

我之前碰巧玩过演示。要回答您的问题,请先设置几何图形以计算项目的高度,然后再设置几何图形()将其放置在布局的底部。 当项目被放置在布局的南部/底部时,一开始你不知道它有多高,对吗


这是GUI编程中的正常做法,例如,要在标签中放置字符串,您将尝试将其放置在任何位置,只是为了计算高度和长度,然后分配正确的rect,然后将字符串放置在您想要的位置。

如果是这样,为什么对于北位置不这样做?因为您知道位置北的方向;而南是反向计算的。为了清楚起见,你有一个面积,比如说100乘100,当放置北时,你把它放在位置(0,0),没问题。放置南时,你首先计算出它的高度,比如说25,然后把它放在位置(0,100-25),对吗?