#!!/usr/bin/python
# Qt modules
from PyQt4 import QtCore, QtGui
import sys
class gui(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle('Grid of buttons')
self.resize(450, 300)
#------------------------------------------------------------------------------
# WIDGETS
#------------------------------------------------------------------------------
self.grid = QtGui.QGridLayout()
btnNum = 1
columnCount = 0
rowCount = 0
while btnNum != 26:
button = QtGui.QPushButton(str(btnNum))
self.grid.addWidget(button, rowCount, columnCount)
btnNum += 1
if columnCount == 4:
columnCount = 0
rowCount += 1
else:
columnCount += 1
#------------------------------------------------------------------------------
# LAYOUT
#------------------------------------------------------------------------------
self.idChannelGroup = QtGui.QGroupBox("My Button Layout")
self.idChannelGroup.setLayout(self.grid)
self.mainLayout = QtGui.QVBoxLayout()
self.mainLayout.addWidget(self.idChannelGroup)
self.setLayout(self.mainLayout)
def main():
app = QtGui.QApplication(sys.argv)
ex = gui()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
大家好...我有两个关于使用 QPushButton 的问题。我对 Qt 很陌生,所以如果这些看起来有点愚蠢,我提前道歉......
首先,有没有办法让 QPushButton 保持按下状态,即保持选中状态?
其次,查询所有按钮,找出当前选中的是哪个按钮?假设单击另一个按钮时它会释放?所以只会选择一个按钮。
任何帮助都会很棒。谢谢你。
干杯