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
QtWS25 Last Chance

How to draw a transparent area selection box

Scheduled Pinned Locked Moved Solved General and Desktop
qtwidgets
9 Posts 4 Posters 823 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.
  • SavizS Offline
    SavizS Offline
    Saviz
    wrote on 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?

    Pl45m4P 1 Reply Last reply
    0
    • JonBJ JonB

      @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?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on 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

      SavizS jeremy_kJ 2 Replies Last reply
      1
      • SavizS Saviz

        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?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on 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

        JonBJ 1 Reply Last reply
        1
        • Pl45m4P Pl45m4

          @Saviz

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

          • https://doc.qt.io/qt-6/qrubberband.html#details
          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #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?

          Pl45m4P 1 Reply Last reply
          1
          • JonBJ JonB

            @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?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on 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

            SavizS jeremy_kJ 2 Replies Last reply
            1
            • Pl45m4P Pl45m4

              @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) ;-)

              SavizS Offline
              SavizS Offline
              Saviz
              wrote on last edited by
              #5

              @Pl45m4 Perfect! I will try this out.

              1 Reply Last reply
              0
              • SavizS Saviz has marked this topic as solved on
              • SavizS Saviz has marked this topic as unsolved on
              • SavizS Saviz has marked this topic as solved on
              • Pl45m4P Pl45m4

                @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) ;-)

                jeremy_kJ Offline
                jeremy_kJ Offline
                jeremy_k
                wrote on 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/

                Pl45m4P 1 Reply Last reply
                0
                • jeremy_kJ jeremy_k

                  @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.

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on 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

                  jeremy_kJ 1 Reply Last reply
                  0
                  • Pl45m4P Pl45m4

                    @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

                    jeremy_kJ Offline
                    jeremy_kJ Offline
                    jeremy_k
                    wrote on last edited by jeremy_k
                    #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/

                    JonBJ 1 Reply Last reply
                    0
                    • jeremy_kJ jeremy_k

                      @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.

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on 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

                      • Login

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