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. Strange initial dialogue location?
Forum Updated to NodeBB v4.3 + New Features

Strange initial dialogue location?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 873 Views 2 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    While testing the initial stages of converting a window from MFC to Qt, I discovered that the initial global location for my About dialogue that was invoked from that window was really "strange". I had deleted the saved geometry for About, and the dialogue was displayed very near the top left of the screen. I added code see where Qt was putting it at the time it was about to show it (ShowEvent):

    QByteArray ba = settings.value("Dialogs/About/geometry").toByteArray();
    if (!ba.isEmpty())
    {
    	restoreGeometry(ba);
    }
    else
    {
    	QPoint point = mapToGlobal(QPoint(0, 0)); 
             etc ..
    

    This gave me x = -129, y = 72 which strikes as a very strange location.

    Is this normal behaviour?

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

      Hi,

      Can you show how you store this information as well ?

      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
      1
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        Huh - I didn't store the QPoint value - I looked at the variable in the debugger.

        D.

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

          You are restoring the geometry, so you did store something at some point, didn't you ?

          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
          1
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by Perdrix
            #5

            Please ignore the if (!ba.isEmpty) {} - it is the ELSE leg I'm concerned about (IOW before any geometry has been saved). The DEFAULT location of the window/widget is "odd" as it has positioned to -129, 72 which seems unusual to me.

            1 Reply Last reply
            0
            • PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by
              #6

              bump ...

              JonBJ 1 Reply Last reply
              0
              • PerdrixP Perdrix

                bump ...

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #7

                @Perdrix
                OK, I found your question confusing. You want us to ignore the code you posted about restoreGeometry(), your question is simply "why does mapToGlobal(QPoint(0, 0)) return -129, 72, is that right?

                mapToGlobal() is a method of QWidget

                Translates the widget coordinate pos to global screen coordinates.

                so what is your this widget? Is it the About box (I'm guessing so)?

                One thought: probably not right, but is it possible that this box does not have a sensible position until after it has been shown (first time)? Could you recall that code from somewhere after is has popped up and see if it gives same values?

                [At the moment I am fighting with (what seems to me) strange behaviour of mapToGlobal() result in the x but not the y direction for a widget. I am finding the x coordinate "moves" further to the right as x increases, yet the y position remains correct. I can't believe mapToGlobal() isn't correct, as I'm sure it gets used a lot, but I don't understand what's going on. Just saying....]

                1 Reply Last reply
                0
                • PerdrixP Offline
                  PerdrixP Offline
                  Perdrix
                  wrote on last edited by
                  #8

                  Yes indeed I'm trying to understand why the DEFAULT widget location is so weird - an x value of -129 is really crazy, and the y is not very logical either. Yes, "this" is the About box pointer.

                  The code in the else leg has code to centre on the user application because the default location was so strange:

                  		//
                  		// Get NATIVE windows ultimate parent
                  		//
                  		HWND hParent = GetDeepStackerDlg(nullptr)->m_hWnd;
                  		RECT r;
                  		GetWindowRect(hParent, &r);
                  
                  		QSize size = this->size();
                  
                  		int top = ((r.top + (r.bottom - r.top) / 2) - (size.height() / 2));
                  		int left = ((r.left + (r.right - r.left) / 2) - (size.width() / 2));
                  		move(left, top);
                  

                  which isn't pretty but does work.

                  D.

                  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