如何使用 pyqt4 在 python 中水平调整组合框的大小

How do I resize the combo box horizontally in python using pyqt4

这是我现在正在实施的代码,我想要的是水平调整组合框的大小以尽可能占据最大 space。 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()

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