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. Get real top left corner of QToolButton
Forum Updated to NodeBB v4.3 + New Features

Get real top left corner of QToolButton

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.5k Views 4 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.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by
    #1

    Hi,

    I have a QToolButton placed on a screen with features multiple frames and other layout widgets and I would like to extend other widgets on click of the button but for positioning of that custom widget, I need to find the top left corner of the QToolButton, I've tried btn.x() and btn.y() but the coordinates returned do clearly not align with the actual position of the button. I wrote a little test program which does not feature any layouts and btn.x() and btn.y() seem to be returning the correct values. How do I get the real position if the QToolButton is positioned inside layouts?

    1 Reply Last reply
    0
    • cerrC cerr

      @mrjj

      if you by "absolute display position" mean the x,y on the screen.

      I see, I wasn't particular enough, I actually mean the position in the Window. I will look at the link, Thank you!

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #6

      @cerr

      If your QToolButton is located in your widget (the one you want to map to), you can use mapToParent or mapTo(widget).
      If it's not a direct parent, you could mapToGlobal first and then mapFromGlobal to get the point in your widget's coordinates.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

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

        Hi,

        QWidget::x value is relative to its parent, did you take that into account ?

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

        cerrC 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          QWidget::x value is relative to its parent, did you take that into account ?

          cerrC Offline
          cerrC Offline
          cerr
          wrote on last edited by
          #3

          @SGaist said in Get real top left corner of QToolButton:

          Hi,

          QWidget::x value is relative to its parent, did you take that into account ?

          OIps, you're right: "This property holds the x coordinate of the widget relative to its parent including any window frame"
          I want to get the absolute display position and should be looking at QRect then I guess... Thanks!

          mrjjM 1 Reply Last reply
          0
          • cerrC cerr

            @SGaist said in Get real top left corner of QToolButton:

            Hi,

            QWidget::x value is relative to its parent, did you take that into account ?

            OIps, you're right: "This property holds the x coordinate of the widget relative to its parent including any window frame"
            I want to get the absolute display position and should be looking at QRect then I guess... Thanks!

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @cerr
            Hi
            You should have a look at
            https://doc.qt.io/qt-5/qwidget.html#mapToGlobal

            if you by "absolute display position" mean the x,y on the screen.

            cerrC 1 Reply Last reply
            3
            • mrjjM mrjj

              @cerr
              Hi
              You should have a look at
              https://doc.qt.io/qt-5/qwidget.html#mapToGlobal

              if you by "absolute display position" mean the x,y on the screen.

              cerrC Offline
              cerrC Offline
              cerr
              wrote on last edited by
              #5

              @mrjj

              if you by "absolute display position" mean the x,y on the screen.

              I see, I wasn't particular enough, I actually mean the position in the Window. I will look at the link, Thank you!

              Pl45m4P 1 Reply Last reply
              0
              • cerrC cerr

                @mrjj

                if you by "absolute display position" mean the x,y on the screen.

                I see, I wasn't particular enough, I actually mean the position in the Window. I will look at the link, Thank you!

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by Pl45m4
                #6

                @cerr

                If your QToolButton is located in your widget (the one you want to map to), you can use mapToParent or mapTo(widget).
                If it's not a direct parent, you could mapToGlobal first and then mapFromGlobal to get the point in your widget's coordinates.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                1

                • Login

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