Important: Please read the Qt Code of Conduct -

Can't set popup x, y before showing

  • I have a menu item from which I am opening a popup with a known id. I am wanting to incorporate some logic to adjust the popup position. In in my menu item handler, if I print the popup's x and y, they are both 0. If I assign nonzero values to both x and y in the same handler and print again, they are still both zero. In other code, I have previously been able to set popup coordinates before opening. Does anyone have any idea what might be going on?

  • Hmmm. I have reproduced this now in a small test app. It looks like the values I set x and y to are in fact respected when the popup is shown but any attempt to examine the values will show them as zero. They are still zero in an onAboutToShow handler I added to the popup, but show the expected values in an onOpened handler.

    I guess this means that care must be taken to avoid code like this:

        popup.y = yUsual; // the 'usual' y value
        var yDelta = calculateAdjustment(); // adjustment if needed
        popup.y += yDelta;

    since presumably this will leave popup.y at yDelta rather than yUsual+ yDelta.

Log in to reply