Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget->height() returns incorrect value in 5.3
Forum Updated to NodeBB v4.3 + New Features

QWidget->height() returns incorrect value in 5.3

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 4.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    ProfRivkin
    wrote on last edited by
    #1

    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.
    Serious BUG!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What OS are you running on ?

      And please post an example code that shows the behavior

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        ProfRivkin
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            ProfRivkin
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              Hi,

              The correct sizes will be calculated if you show() the widget.

              @
              QWidget w;
              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/

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zeljko
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  ProfRivkin
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    zeljko
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved