我有一个按钮列表,每个按钮对应于包含标签和lineEdit的网格布局中的一行。当我按下这些按钮之一时,我希望相应的行亮起。如何实现行的“点亮”?
以下代码显示了我正在谈论的布局。
import sys
from PySide import QtGui
from PySide import QtCore
from PySide.QtGui import *
from PySide.QtCore import *
class MainWindow(QDialog):
def __init__(self):
super(MainWindow, self).__init__()
self.createLayout()
self.setLayout(self.mainLayout)
self.show()
def createLayout(self):
self.mainLayout = QVBoxLayout()
self.button1 = QPushButton("Button1")
self.button2 = QPushButton("Button2")
self.button3 = QPushButton("Button3")
#self.button1.clicked.connect(self.onButton1Press)
#self.button2.clicked.connect(self.onButton2Press)
#self.button3.clicked.connect(self.onButton3Press)
self.HLay = QHBoxLayout()
self.HLay.addWidget(self.button1)
self.HLay.addWidget(self.button2)
self.HLay.addWidget(self.button3)
self.mainLayout.addLayout(self.HLay)
self.gridLay = QGridLayout()
label1 = QLabel("Label1")
line1 = QLineEdit()
self.gridLay.addWidget(label1,0,0)
self.gridLay.addWidget(line1,0,1)
label2 = QLabel("Label2")
line2 = QLineEdit()
self.gridLay.addWidget(label2,1,0)
self.gridLay.addWidget(line2,1,1)
label3 = QLabel("Label3")
line3 = QLineEdit()
self.gridLay.addWidget(label3,2,0)
self.gridLay.addWidget(line3,2,1)
self.mainLayout.addLayout(self.gridLay)
#def onButton1Press(self):
#Highlight row in self.gridLay that contains label1 and line1
#def onButton2Press(self):
#Highlight row in self.gridLay that contains label2 and line2
#def onButton3Press(self):
#Highlight row in self.gridLay that contains label3 and line3
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWin = MainWindow()
ret = app.exec_()
sys.exit( ret )
答案 0 :(得分:0)
查看从QGraphicsEffect派生的类。可以使用QWidget :: setGraphicsEffect方法将图形效果应用于窗口小部件,您可以根据需要编写自己的效果。