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. How to draw a transparent area selection box
Forum Update on Monday, May 27th 2025

How to draw a transparent area selection box

Scheduled Pinned Locked Moved Solved General and Desktop
qtwidgets
9 Posts 4 Posters 850 Views
  • 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.
  • S Offline
    S Offline
    Saviz
    wrote on 4 Dec 2023, 05:57 last edited by
    #1

    I have a QPushButton connected to a slot that minimizes my QMainWindow. After minimizing the window, I intend to draw a transparent rectangular box with only a border. The purpose is to create a selection box, similar to how screen capture apps function where they allow the user to select an area on their screen and display a width and height in the middle. I aim for users to drag and resize this box using their mouse. Is there an example demonstrating this functionality in QtWidgets version 6.6.1?

    P 1 Reply Last reply 4 Dec 2023, 13:27
    0
    • J JonB
      4 Dec 2023, 13:30

      @Pl45m4
      I don't know the answer to this. The OP (if I understand right) wants to draw a box on the screen/desktop, outside of the Qt application (that is minimized). Can/how you tell QWidgets to go outside the application window? Do you create a widget with no parent and screen coordinates and that's allowed?

      P Offline
      P Offline
      Pl45m4
      wrote on 4 Dec 2023, 14:01 last edited by
      #4

      @JonB said in How to draw a transparent area selection box:

      Can/how you tell QWidgets to go outside the application window?

      QRubberBand is a widget itself and you can show it any time.

      Maybe even a QRubberBand subclass with an inbuilt timer to update the mouse pos (QCursor::pos) of the drag (because no parent window/widget = no mouseMoveEvent) ;-)


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

      ~E. W. Dijkstra

      S J 2 Replies Last reply 4 Dec 2023, 15:48
      1
      • S Saviz
        4 Dec 2023, 05:57

        I have a QPushButton connected to a slot that minimizes my QMainWindow. After minimizing the window, I intend to draw a transparent rectangular box with only a border. The purpose is to create a selection box, similar to how screen capture apps function where they allow the user to select an area on their screen and display a width and height in the middle. I aim for users to drag and resize this box using their mouse. Is there an example demonstrating this functionality in QtWidgets version 6.6.1?

        P Offline
        P Offline
        Pl45m4
        wrote on 4 Dec 2023, 13:27 last edited by
        #2

        @Saviz

        QRubberBand? It's for selection of a boundingBox by mouse

        • https://doc.qt.io/qt-6/qrubberband.html#details

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

        ~E. W. Dijkstra

        J 1 Reply Last reply 4 Dec 2023, 13:30
        1
        • P Pl45m4
          4 Dec 2023, 13:27

          @Saviz

          QRubberBand? It's for selection of a boundingBox by mouse

          • https://doc.qt.io/qt-6/qrubberband.html#details
          J Offline
          J Offline
          JonB
          wrote on 4 Dec 2023, 13:30 last edited by JonB 12 Apr 2023, 13:31
          #3

          @Pl45m4
          I don't know the answer to this. The OP (if I understand right) wants to draw a box on the screen/desktop, outside of the Qt application (that is minimized). Can/how you tell QWidgets to go outside the application window? Do you create a widget with no parent and screen coordinates and that's allowed?

          P 1 Reply Last reply 4 Dec 2023, 14:01
          1
          • J JonB
            4 Dec 2023, 13:30

            @Pl45m4
            I don't know the answer to this. The OP (if I understand right) wants to draw a box on the screen/desktop, outside of the Qt application (that is minimized). Can/how you tell QWidgets to go outside the application window? Do you create a widget with no parent and screen coordinates and that's allowed?

            P Offline
            P Offline
            Pl45m4
            wrote on 4 Dec 2023, 14:01 last edited by
            #4

            @JonB said in How to draw a transparent area selection box:

            Can/how you tell QWidgets to go outside the application window?

            QRubberBand is a widget itself and you can show it any time.

            Maybe even a QRubberBand subclass with an inbuilt timer to update the mouse pos (QCursor::pos) of the drag (because no parent window/widget = no mouseMoveEvent) ;-)


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

            ~E. W. Dijkstra

            S J 2 Replies Last reply 4 Dec 2023, 15:48
            1
            • P Pl45m4
              4 Dec 2023, 14:01

              @JonB said in How to draw a transparent area selection box:

              Can/how you tell QWidgets to go outside the application window?

              QRubberBand is a widget itself and you can show it any time.

              Maybe even a QRubberBand subclass with an inbuilt timer to update the mouse pos (QCursor::pos) of the drag (because no parent window/widget = no mouseMoveEvent) ;-)

              S Offline
              S Offline
              Saviz
              wrote on 4 Dec 2023, 15:48 last edited by
              #5

              @Pl45m4 Perfect! I will try this out.

              1 Reply Last reply
              0
              • S Saviz has marked this topic as solved on 4 Dec 2023, 15:49
              • S Saviz has marked this topic as unsolved on 4 Dec 2023, 15:50
              • S Saviz has marked this topic as solved on 4 Dec 2023, 15:50
              • P Pl45m4
                4 Dec 2023, 14:01

                @JonB said in How to draw a transparent area selection box:

                Can/how you tell QWidgets to go outside the application window?

                QRubberBand is a widget itself and you can show it any time.

                Maybe even a QRubberBand subclass with an inbuilt timer to update the mouse pos (QCursor::pos) of the drag (because no parent window/widget = no mouseMoveEvent) ;-)

                J Offline
                J Offline
                jeremy_k
                wrote on 4 Dec 2023, 16:59 last edited by
                #6

                @Pl45m4 said in How to draw a transparent area selection box:

                Maybe even a QRubberBand subclass with an inbuilt timer to update the mouse pos (QCursor::pos) of the drag (because no parent window/widget = no mouseMoveEvent) ;-)

                A timer shouldn't be necessary. Implement the mouse events in the subclass. The QRubberBand, being a widget without a parent, will create its own window.

                Asking a question about code? http://eel.is/iso-c++/testcase/

                P 1 Reply Last reply 4 Dec 2023, 19:04
                0
                • J jeremy_k
                  4 Dec 2023, 16:59

                  @Pl45m4 said in How to draw a transparent area selection box:

                  Maybe even a QRubberBand subclass with an inbuilt timer to update the mouse pos (QCursor::pos) of the drag (because no parent window/widget = no mouseMoveEvent) ;-)

                  A timer shouldn't be necessary. Implement the mouse events in the subclass. The QRubberBand, being a widget without a parent, will create its own window.

                  P Offline
                  P Offline
                  Pl45m4
                  wrote on 4 Dec 2023, 19:04 last edited by
                  #7

                  @jeremy_k

                  But then you only have the mouseMoveEvents where the rubberband already is and not where you want to move it, right?!
                  You want to track the mouse pos over the whole screen and then click and drag to adjust the rectanhe to capture or do whatever you like


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

                  ~E. W. Dijkstra

                  J 1 Reply Last reply 4 Dec 2023, 19:20
                  0
                  • P Pl45m4
                    4 Dec 2023, 19:04

                    @jeremy_k

                    But then you only have the mouseMoveEvents where the rubberband already is and not where you want to move it, right?!
                    You want to track the mouse pos over the whole screen and then click and drag to adjust the rectanhe to capture or do whatever you like

                    J Offline
                    J Offline
                    jeremy_k
                    wrote on 4 Dec 2023, 19:20 last edited by jeremy_k 12 Apr 2023, 19:24
                    #8

                    @Pl45m4 said in How to draw a transparent area selection box:

                    @jeremy_k

                    But then you only have the mouseMoveEvents where the rubberband already is and not where you want to move it, right?!

                    That's true, if there is no rubber band window to start. I was thinking of the macOS screen capture interface that opens with the previously used geometry, or a default for the first use.

                    If there's no initial underlying window belonging to the application, the window manager windowing system is going to have to cooperate and not deliver the mouse button press to something else.

                    Asking a question about code? http://eel.is/iso-c++/testcase/

                    J 1 Reply Last reply 4 Dec 2023, 19:23
                    0
                    • J jeremy_k
                      4 Dec 2023, 19:20

                      @Pl45m4 said in How to draw a transparent area selection box:

                      @jeremy_k

                      But then you only have the mouseMoveEvents where the rubberband already is and not where you want to move it, right?!

                      That's true, if there is no rubber band window to start. I was thinking of the macOS screen capture interface that opens with the previously used geometry, or a default for the first use.

                      If there's no initial underlying window belonging to the application, the window manager windowing system is going to have to cooperate and not deliver the mouse button press to something else.

                      J Offline
                      J Offline
                      JonB
                      wrote on 4 Dec 2023, 19:23 last edited by
                      #9

                      @jeremy_k said in How to draw a transparent area selection box:

                      If there's no initial underlying window belonging to the application, the window manager is going to have to cooperate and not deliver the mouse button press to something else.

                      That's the sort of thing I was thinking of. I didn't know plain applications had access to the visual desktop, only to the windows the manager allowed it to create. But I don't really know.

                      1 Reply Last reply
                      0

                      1/9

                      4 Dec 2023, 05:57

                      • Login

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