前提・実現したいこと
PyQt5を使い、ウィンドウを細長くしたもの(エッジバー)を左右上に配置し、クリックしたときにアクションをさせています。
この時、エッジバー以外をクリックしたときにもアクションをさせたいのですが、どのように実装すればよいでしょうか?
例えばこの画像でいうと灰色のウィンドウをクリックしたときに、アクションをさせたいです。
よろしくお願いいたします。
該当のソースコード
Python
1''' 2メインウィンドウの左右、上に太さ1pixelのエッジバーを表示する 3エッジバーをクリックすると、hello()を呼ぶ 4エッジバーを右クリックすると終了する 5 6エッジバー以外の領域をクリックしたときにbye()を呼びたい 7''' 8 9from re import S 10from PyQt5.QtWidgets import QApplication, QWidget 11from PyQt5.QtCore import Qt, QEvent 12import sys 13 14class EdgeWindow(QWidget): 15 16 def __init__( self, p_wnd, ): 17 super().__init__(p_wnd) 18 19 self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint ) 20 self.setWindowOpacity(1) 21 self.installEventFilter(self) 22 self.show() 23 24 def eventFilter(self, obj, event): 25 if event.type() == QEvent.MouseButtonPress: 26 if event.button() == Qt.LeftButton: 27 self.func() 28 return True 29 if event.button() == Qt.RightButton: 30 sys.exit() 31 return False 32 33class EdgeBar(QWidget): 34 def __init__( self, LT=None, LB=None, RT=None,RB=None, TL=None, TR=None, DEFAULT=None ): 35 super().__init__() 36 37 self.hide() 38 39 scr = QApplication.primaryScreen().availableGeometry() 40 41 if LT != None: #LeftTop 42 self.LTwin = EdgeWindow(self) 43 self.LTwin.func = LT 44 self.LTwin.setGeometry( 0, 0, 1, int(scr.height()/2)) 45 if LB != None: #LeftBottom 46 self.LBwin = EdgeWindow(self) 47 self.LBwin.func = LB 48 self.LBwin.setGeometry( 0, int((scr.top()+scr.height())/2), 1, int(scr.height()/2)) 49 if RT != None: #RightTop 50 self.RTwin = EdgeWindow(self) 51 self.RTwin.func = RT 52 self.RTwin.setGeometry( scr.right(), scr.top(), scr.right(), int(scr.height()/2)) 53 if RB != None: #RightBottom 54 self.RBwwin = EdgeWindow(self) 55 self.RBwwin.func = RB 56 self.RBwwin.setGeometry( scr.right(), int((scr.top()+scr.height())/2), scr.right(), int(scr.height()/2)) 57 if TL != None: #TopLeft 58 self.TLwin = EdgeWindow(self) 59 self.TLwin.func = TL 60 self.TLwin.setGeometry( 0, 0, int(scr.width()/2), 1) 61 if TR != None: #TopRight 62 self.TRwin = EdgeWindow(self) 63 self.TRwin.func = TR 64 self.TRwin.setGeometry( int((scr.left()+scr.width())/2), 0, int(scr.width()/2), 1 ) 65 if DEFAULT != None: 66 ''' 67 self.xxx.func = DEFAULT 68 69 ここの処理がわからないです 70 ''' 71 72def hello(): 73 print("hello!") 74 75def bye(): 76 print("bye!") 77 78if __name__ == '__main__': 79 app = QApplication(sys.argv) 80 edgebar = EdgeBar(LT=hello, LB=hello, RT=hello,RB=hello, TL=hello, TR=hello, DEFAULT=bye ) 81 sys.exit(app.exec_())

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/14 12:56 編集
2022/02/14 13:22
2022/02/14 16:48 編集
2022/02/15 13:08