Question

The follow snippet results in my compilation yielding "error: passing 'const QRect' as 'this' argument of 'void QRect::setHeight(int)' discards qualifiers [-fpermissive]".

How can I fix this and also I've noticed that if I were to replace h -= 80; with h--;, the compiler does not complain.

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

Solution

geometry() returns a const reference to a QRect object inside QTableWidget.

It's meant to be a read-only getter. You should take a copy, modify it and set it back with setGeometry setter function:

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

OTHER TIPS

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

It would seem that geometry() in datumTable returns a const QRect. Not an easy fix unless there is a non-const version as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top