前提・実現したいこと
PyQt5を使い、ウィンドウを細長くしたもの(エッジバー)を左右上に配置し、クリックしたときにアクションをさせています。
この時、エッジバー以外をクリックしたときにもアクションをさせたいのですが、どのように実装すればよいでしょうか?
例えばこの画像でいうと灰色のウィンドウをクリックしたときに、アクションをさせたいです。
よろしくお願いいたします。
該当のソースコード
Python
''' メインウィンドウの左右、上に太さ1pixelのエッジバーを表示する エッジバーをクリックすると、hello()を呼ぶ エッジバーを右クリックすると終了する エッジバー以外の領域をクリックしたときにbye()を呼びたい ''' from re import S from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtCore import Qt, QEvent import sys class EdgeWindow(QWidget): def __init__( self, p_wnd, ): super().__init__(p_wnd) self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint ) self.setWindowOpacity(1) self.installEventFilter(self) self.show() def eventFilter(self, obj, event): if event.type() == QEvent.MouseButtonPress: if event.button() == Qt.LeftButton: self.func() return True if event.button() == Qt.RightButton: sys.exit() return False class EdgeBar(QWidget): def __init__( self, LT=None, LB=None, RT=None,RB=None, TL=None, TR=None, DEFAULT=None ): super().__init__() self.hide() scr = QApplication.primaryScreen().availableGeometry() if LT != None: #LeftTop self.LTwin = EdgeWindow(self) self.LTwin.func = LT self.LTwin.setGeometry( 0, 0, 1, int(scr.height()/2)) if LB != None: #LeftBottom self.LBwin = EdgeWindow(self) self.LBwin.func = LB self.LBwin.setGeometry( 0, int((scr.top()+scr.height())/2), 1, int(scr.height()/2)) if RT != None: #RightTop self.RTwin = EdgeWindow(self) self.RTwin.func = RT self.RTwin.setGeometry( scr.right(), scr.top(), scr.right(), int(scr.height()/2)) if RB != None: #RightBottom self.RBwwin = EdgeWindow(self) self.RBwwin.func = RB self.RBwwin.setGeometry( scr.right(), int((scr.top()+scr.height())/2), scr.right(), int(scr.height()/2)) if TL != None: #TopLeft self.TLwin = EdgeWindow(self) self.TLwin.func = TL self.TLwin.setGeometry( 0, 0, int(scr.width()/2), 1) if TR != None: #TopRight self.TRwin = EdgeWindow(self) self.TRwin.func = TR self.TRwin.setGeometry( int((scr.left()+scr.width())/2), 0, int(scr.width()/2), 1 ) if DEFAULT != None: ''' self.xxx.func = DEFAULT ここの処理がわからないです ''' def hello(): print("hello!") def bye(): print("bye!") if __name__ == '__main__': app = QApplication(sys.argv) edgebar = EdgeBar(LT=hello, LB=hello, RT=hello,RB=hello, TL=hello, TR=hello, DEFAULT=bye ) sys.exit(app.exec_())
まだ回答がついていません
会員登録して回答してみよう