Results 1 to 4 of 4

Thread: Drawing on top of all widgets

  1. #1
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    7
    Qt products
    Platforms
    Windows

    Default Drawing on top of all widgets

    I create a line graph, using the button to create a crosshair on the graph that follows the mouse movement.
    Here I displayed in the GIF what it looks like:
    https://gifyu.com/image/0kvX

    I also add various graphs below and want the crosshair to capture these additional graphs.
    The spaces between graphs should also be drawn with crosshair lines.
    Where the cursor is located, you need to draw a vertical and horizontal line. in other cases, only draw a vertical line.
    Here's the picture:
    https://gifyu.com/image/0kmV

    I create a crosshair using "QtChart.QLineSeries()".
    The simplest thing that comes to mind is to create these two lines in each chart and hide the non-main horizontal lines.

    What can you recommend?

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Drawing on top of all widgets

    Maybe you could render the multiple graphs onto a QPixmap, paint the QPixmap and then overpaint it with the crosshair.

  3. The following user says thank you to Cruz for this useful post:

    quant (13th December 2020)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Drawing on top of all widgets

    What can you recommend?
    Look at QRubberBand. You can derive from it and override the paint event if you want to draw crosshairs instead of a rectangle or line.
    Last edited by d_stranz; 9th December 2020 at 17:53.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    quant (13th December 2020)

  6. #4
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    7
    Qt products
    Platforms
    Windows

    Default Re: Drawing on top of all widgets

    Quote Originally Posted by d_stranz View Post
    Look at QRubberBand. You can derive from it and override the paint event if you want to draw crosshairs instead of a rectangle or line.
    Thank you, it turned out what need. https://gifyu.com/image/0Uby
    The documentation describes that you can draw a line instead of a rectangle: QRubberBand::Line.
    I didn't find a specific example to draw lines in.
    I drew narrow rectangles so that they look like lines.

    Qt Code:
    1. class _RubberBand(QtWidgets.QWidget):
    2. def __init__(self, parent=None):
    3. super(_RubberBand, self).__init__(parent)
    4.  
    5. self.setMouseTracking(True)
    6. self.resize(self.window().size()) # +++ <<<-----
    7.  
    8. self.mouseMovePos = None
    9.  
    10. self._band = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Line, self)
    11. self._band_ = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Line, self)
    12. self._band.setGeometry(350, 0, 2, 550)
    13. self._band_.setGeometry(0, 250, 700, 2)
    14. self._band.show()
    15. self._band_.show()
    16. self.show()
    17.  
    18. def mouseMoveEvent(self, event):
    19. a = QtCore.QPoint(event.pos().x(), self._band.maximumHeight())
    20. b = QtCore.QPoint(event.pos().x()+1, 2)
    21. a1 = QtCore.QPoint(0, event.pos().y())
    22. b1 = QtCore.QPoint(self._band.maximumWidth(), event.pos().y()+1)
    23. self._band.setGeometry(QtCore.QRect(a, b).normalized())
    24. self._band_.setGeometry(QtCore.QRect(a1, b1).normalized())
    25.  
    26. self.resize(self.window().size())
    27. self._band.update()
    28. self._band_.update()
    29. self.update()
    To copy to clipboard, switch view to plain text mode 

    And also the "Open", "Close" and scrollbar buttons become inactive while the crosshair is running
    Last edited by quant; 13th December 2020 at 12:42.

Similar Threads

  1. Replies: 0
    Last Post: 31st October 2014, 08:42
  2. Flickering when drawing Qt widgets over an OpenGL window
    By ksierens in forum Qt Programming
    Replies: 0
    Last Post: 31st May 2010, 15:31
  3. Drawing widgets inside a Qt application
    By aughey in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2010, 09:45
  4. Replies: 2
    Last Post: 18th March 2008, 00:49
  5. Drawing over content widgets? (overlay)
    By sertrem in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 23:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.