Python 3.x 如何将此代码转换为PyQt5?
我有这个代码我想把这个代码从PyQt4转换成PyQt5 这是密码Python 3.x 如何将此代码转换为PyQt5?,python-3.x,layout,pyqt4,pyqt5,Python 3.x,Layout,Pyqt4,Pyqt5,我有这个代码我想把这个代码从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
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
试试看:
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()
将
从PyQt4导入QtGui、QtCore
更改为从PyQt5导入QtWidgets、QtGui、QtCore
和QtGui.Q..
更改为QtWidgets.Q..