如何使用pyqt4

时间:2016-01-28 09:58:34

标签: python pyqt4

这是我现在正在实现的代码,我想要的是水平调整组合框的大小以占用最大空间。 combo.resize只允许我选择垂直拉伸它。

import sys
from PyQt4 import QtGui, QtCore

class phaseOne(QtGui.QWidget):

   def __init__(self):
        super(phaseOne, self).__init__()
        self.initUI()

    def initUI(self):

        self.resize(350,150)
        self.center()

        self.setWindowTitle('Programmer')

        self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint)

        QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))

        btn = QtGui.QPushButton('Next', self)
        btn.setToolTip('proceed to next step')
        btn.resize(btn.sizeHint())
        btn.move(250, 110)

        btn = QtGui.QPushButton('Exit', self)
        btn.setToolTip('exit the application')
        btn.resize(btn.sizeHint())
        btn.move(175, 110)                 

        self.lbl = QtGui.QLabel("Select your Programming Language",self) 

        combo = QtGui.QComboBox(self)
        combo.addItem("C")
        combo.addItem("C++")
        combo.addItem("JAVA")
        combo.addItem("Ruby")
        combo.addItem("Python")

        #adjusting the combo box
        #combo.resize(50,20)
        combo.move(50,50)
        self.lbl.move(50,25)

        self.show()

def center(self):
    qr = self.frameGeometry()
    cp = QtGui.QDesktopWidget().availableGeometry().center()
    qr.moveCenter(cp)
    self.move(qr.topLeft())

def closeEvent(self, event):

    reply = QtGui.QMessageBox.question(self, 'Message',
        "Are you sure to quit?", QtGui.QMessageBox.Yes | 
        QtGui.QMessageBox.No, QtGui.QMessageBox.No)

    if reply == QtGui.QMessageBox.Yes:
        event.accept()
    else:
        event.ignore()

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


if __name__ == '__main__':
    main()

1 个答案:

答案 0 :(得分:0)

所以,我解决了我的问题。 combo.resize选项提供了它,但我不知道如何使用它。定位由combo.move处理,并且水平拉伸,第一个值将在combo.resize中更改。