如何使用pyqt4增加gridlayout中特定按钮的大小

How to increase the size of the particular push button in gridlayout uisng pyqt4

在这个程序中,我想创建一个数字键盘,就像 keypad.In 我使用 gridlayout 创建了数字键盘,但我没有得到给定图像中的数字键盘,任何人都可以帮助我如何增加此 gridlayot 中按钮的大小。 下面是我的代码:

import sys
from PyQt4 import QtGui

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):

        grid = QtGui.QGridLayout()
        self.setLayout(grid)

        names = [
                 '7', '8', '9', '-',
                '4', '5', '6', '+',
                 '1', '2', '3', 'enter',
                '0', '.',  '']

        positions = [(i,j) for i in range(4) for j in range(4)]

        for position, name in zip(positions, names):

            if name == '':
                continue
            button = QtGui.QPushButton(name)
            grid.addWidget(button, *position)

        self.move(300, 150)
        self.setWindowTitle('Calculator')
        self.show()

def main():
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

抱歉,我正在使用 PyQt5

import sys
#from PyQt4 import QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class Example(QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):

        grid = QGridLayout()
        self.setLayout(grid)

        names = [
                '7', '8', '9', '-',
                '4', '5', '6', '+',
                '1', '2', '3', 'enter',
                '0', '',  '.']

        positions = [(i,j) for i in range(4) for j in range(4)]

        for position, name in zip(positions, names):

            if name == '':
                continue
            button = QPushButton(name)
            button.clicked.connect(self.buttonClicked) 

            button.setMinimumWidth(50)
            button.setMinimumHeight(50)

            if button.text() == 'enter':
                button.setMinimumHeight(110)
                grid.addWidget(button, *position, 2, 1) 
            elif button.text() == '0':
                grid.addWidget(button, *position, 1, 2) 
            else:
                grid.addWidget(button, *position, 1, 1)

    def buttonClicked(self):
        print(self.sender().text())

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    ex.show()
    ex.setWindowTitle('Calculator')
    ex.setGeometry(300, 150, 250, 250)
    sys.exit(app.exec_())