Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-30275

QWidget::pos returns wrong position for maximized windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 4.8.4
    • GUI: Window management
    • None
    • OSX

    Description

      The following code example creates a single widget, maximizes it and reports the values returned by QWidget::pos and an QPoint(0,0) mapped to global coordinates which should be the same thing (plus any OS-supplied decoration).

      #include <QtGui>
      
      int main(int argc, char *argv[])
      {
      	QApplication a(argc, argv);
      	
      	QWidget w;
      	w.show();
      	//w.showMaximized();
      	
      	QPoint p = w.pos();
      	qDebug() << "pos" << p.x() << p.y();
      	
      	p = w.mapToGlobal(QPoint());
      	qDebug() << "corrected pos" << p.x() << p.y();
      	
      	return a.exec();
      }
      
      

      On my Mac it prints the following:
      pos 640 410
      corrected pos 640 432

      Which is reasonable. I would expect 'corrected pos' to return a slightly offset value as it must account for the window decoration.

      But if show() is replaced by showMaximized() it prints the following:
      pos 640 410
      corrected pos 0 44

      The 'corrected pos' is as expected (44 is the height of title bar).

      But the 640x410 provided by QWidget::pos is now completely wrong.

      On MS Windows, the results are almost the same (and identical if the window is frameless).

      In our product, we use QWidget::pos and QWidget::geometry to center child windows above the main window. These appear in the wrong position when the parent window is maximized.

      The workaround is to use the mapToGlobal(QPoint()) trick.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            danny77uk Daniel
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes