def __init__(self, parent=None):
super(ViewerLabel, self).__init__(parent)
self.setMouseTracking(True)
self.setAlignment(Qt.AlignCenter)
def enterEvent(self,event):
button.setStyleSheet("background-color:#45b545;")
def leaveEvent(self,event):
button.setStyleSheet("background-color:yellow;")
def main():
label_01 = ViewerLabel(“label 01â€)
label_02 = ViewerLabel(“label 02â€)
label_03 = ViewerLabel(“label 03â€)
label_04 = ViewerLabel(“label 04â€)
label_05 = ViewerLabel(“label 05â€)
label_06 = ViewerLabel(“label 06â€)
layout.addwidget(label_01, 0, 1)
layout.addwidget(label_02, 0, 2)
layout.addwidget(label_03, 1, 1)
layout.addwidget(label_04, 1, 2)
layout.addwidget(label_05, 2, 1)
layout.addwidget(label_06, 2, 2)
layout.setSpacing(10)
scrollArea.setWidget(layout)
window.setLayout(scrollArea)
window.setFixedSize(400,500)
window.show()
return app.exec_()
if __name__ == __main__:
main()
class ViewerLabel(QLabel):
def __init__(self, parent=None):
super(ViewerLabel, self).__init__(parent)
self.setMouseTracking(True)
self.setAlignment(Qt.AlignCenter)
def enterEvent(self,event):
button.setStyleSheet("background-color:#45b545;")
def leaveEvent(self,event):
button.setStyleSheet("background-color:yellow;")
def main():
layout = QGridLayout()
scrollArea = QScrollArea()
label_01 = ViewerLabel(“label 01â€)
label_02 = ViewerLabel(“label 02â€)
label_03 = ViewerLabel(“label 03â€)
label_04 = ViewerLabel(“label 04â€)
label_05 = ViewerLabel(“label 05â€)
label_06 = ViewerLabel(“label 06â€)
layout.addwidget(label_01, 0, 1)
layout.addwidget(label_02, 0, 2)
layout.addwidget(label_03, 1, 1)
layout.addwidget(label_04, 1, 2)
layout.addwidget(label_05, 2, 1)
layout.addwidget(label_06, 2, 2)
layout.setSpacing(10)
scrollArea.setWidget(layout)
window.setLayout(scrollArea)
window.setFixedSize(400,500)
window.show()
return app.exec_()
if __name__ == __main__:
main()
To copy to clipboard, switch view to plain text mode
Bookmarks