Reputation: 13
I am trying to simulate a paint brush with Qt buttons instead of pixels. I have overloaded the event filter on each button and can detect eventHover or eventFilter only when the mouse is not pressed down. I want to hold mouse click down and detect if i collide with a button. Any suggestions as to what i should do from here?
def eventFilter(self, a0, a1):
if a1.type() == QtCore.QEvent.Enter:
if(self.mouse.pressed):
ui_logic.square_press(self,"red")
return super().eventFilter(a0, a1)
def square_press(button,color):
style = "QPushButton{background-color:" + color + "}"
button.setStyleSheet(style)
Thank you
Upvotes: 0
Views: 100
Reputation: 13
What i ended up doing is tracking the mouse and getting the widget at a location. Example code:
class TrackMouse(QtWidgets.QWidget):
pressed = False
def __init__(self,obj,app):
self.app = app
super(QtWidgets.QWidget, self).__init__()
def eventFilter(self, a0, event):
if event.type() == QtCore.QEvent.MouseMove:
if(event.buttons() == QtCore.Qt.MouseButton.LeftButton):
widget = self.app.widgetAt(event.globalPos())
print(widget.__class__)
if(widget.__class__ is CustomButtom):
ui_logic.square_press(widget,"red")
return super().eventFilter(a0, event)
Upvotes: 0