Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QWidget->height() returns incorrect value in 5.3
I compared builds with 5.2.1 and 5.3 after finding this bug. I can confirm that 5.2.1 works fine and 5.3 does NOT.
For example, create a QMainWindow with a QWidget of some size in QtCreator.
In C++ code, read the QWidgets' height (int h = ui->widget->height()) In 5.2.1 this will be the height you set, in 5.3, it appears to be 1/10th the size.
What OS are you running on ?
And please post an example code that shows the behavior
Ubuntu 14.04, Ubuntu 13.10 and Windows 8.1 all tried.
The example of the code was posted to the original message.
int h = ui->widget->height();
Run this in your debugger and check the value of h. You will see there is a huge difference between versions.
That's not a usable example. You are using a designer based widget so I don't know if you put any layout on it, if you set your widget as central widget etc. Also you don't tell when or where you are getting the widget's height.
Just try the simple example I gave and you will see.
I did say, exactly in the example how to call the height() method.
Do it any way you like and it all comes out the same.
The correct sizes will be calculated if you show() the widget.
w.setGeometry(0, 0, 400, 300);
auto layout = new QVBoxLayout; auto textEdit = new QTextEdit; layout->addWidget(textEdit); w.setLayout(layout); qDebug() << "Before showing: " << textEdit->height(); w.show(); qDebug() << "After showing: " << textEdit->height();
My output is:
Before showing: 480
After showing: 278
As a workaround, try calling this->show() before ui->widget->height().
Since this behaviour breaks old programs, please report it to http://bugreports.qt-project.org/
zeljko last edited by
That's pretty wrong and it breaks everything. Geometry shuold be calculated and supplied as soon as possible,no matter if it's visible or not. I understand why on X11 frameGeometry() is tricky , but geometry should be correct all the time.
I guess that this is really ugly bug and if not then it's bad behaviour.
Firstly, one should not call this in Main unless you really have to.
We dont, we have this with the widgets already showing. Typically from some slot called when a button is pressed. The widget in our case, never changes size during the entire applicaiton run.
This thread is just to let people know there is a bug. If someone at Qt wants to write a bug report, they can but I wont after all the bad prior experiences.
zeljko last edited by
I've also had bad expiriences with issues reporting, but must say that also I had good expiriences. Depends on person who is responsible for issue, so generally it's bad idea to NOT report such issue.