Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.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++ 无法从QRect修改高度值_C++_Qt_Qrect - Fatal编程技术网

C++ 无法从QRect修改高度值

C++ 无法从QRect修改高度值,c++,qt,qrect,C++,Qt,Qrect,以下代码段导致我的编译产生“错误:将'const QRect'作为'void QRect::setHeight(int)'的'this'参数传递”。丢弃限定符[-fppermissive]” 我如何解决这个问题,我也注意到,如果我要替换h-=80;用h--;,编译器没有抱怨 int h = this->geometry().height(); h -= 80; ui->datumTable->geometry().setHeight(h); 似乎datumTable中的geo

以下代码段导致我的编译产生“错误:将'const QRect'作为'void QRect::setHeight(int)'的'this'参数传递”。丢弃限定符[-fppermissive]”

我如何解决这个问题,我也注意到,如果我要替换h-=80;用h--;,编译器没有抱怨

int h = this->geometry().height();
h -= 80;
ui->datumTable->geometry().setHeight(h);

似乎
datumTable
中的
geometry()。除非有一个非常量版本,否则这不是一个简单的解决方案

几何体()

它是一个只读的getter。您应该复制、修改并使用
setGeometry
setter函数将其设置回:

QRect rect = this->geometry();
int h = rect.height();
rect.setHeight(h - 80);
ui->datumTable->setGeometry(rect);

datumTable
对象或
geometry
函数已标记为
const
。也就是说,它们不能被修改。为什么QTableWidget会有一个setHeight方法呢?很确定同样的代码在windows上的qt中工作过,这可能是linux变体的问题/错误吗?这不一定是个困难的问题problem@johnsonwi因为返回的值是常量引用,所以编译器不允许您修改它。
QRect g = this->geometry().height();
g.setHeight(g.height()-80);
ui->datumTable->setGeometry(g);