我有这个代码我想将此代码从PyQt4转换为PyQt5
这是代码
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
left = QtGui.QFrame(self)
left.setFrameShape(QtGui.QFrame.StyledPanel)
right = QtGui.QFrame(self)
right.setFrameShape(QtGui.QFrame.StyledPanel)
splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter.addWidget(left)
splitter.addWidget(right)
splitter.setStretchFactor(1, 1)
splitter.setSizes([125, 150])
hbox.addWidget(splitter)
self.setLayout(hbox)
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QtGui.QSplitter')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
如何将此代码转换为pyqt5
答案 0 :(得分:0)
试一试:
import sys
#from PyQt4 import QtGui, QtCore
from PyQt5 import Qt
class Example(Qt.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
hbox = Qt.QHBoxLayout(self)
left = Qt.QFrame(self)
left.setFrameShape(Qt.QFrame.StyledPanel)
left.setStyleSheet('background-color:lightblue; color: white; font-weight: bold;')
labelLeft = Qt.QLabel(" \n left = Qt.QFrame(self)", left)
right = Qt.QFrame(self)
right.setFrameShape(Qt.QFrame.StyledPanel)
labelRight = Qt.QLabel(" \n right = Qt.QFrame(self)", right)
splitter = Qt.QSplitter(Qt.Qt.Horizontal)
splitter.addWidget(left)
splitter.addWidget(right)
splitter.setStretchFactor(1, 1)
splitter.setSizes([125, 150])
hbox.addWidget(splitter)
self.setLayout(hbox)
Qt.QApplication.setStyle(Qt.QStyleFactory.create('Cleanlooks'))
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Qt.QSplitter')
self.show()
def main():
app = Qt.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()