[英]Qt module alternative for PyQt6
我只是將我的應用程序從 PyQt5 遷移到 PyQt6。 我了解 Qt 模塊已在 Qt6 中刪除。 我有'Qt.AlignCenter'、'Qt.ToolButtonTextUnderIcon'、'Qt.LeftToolBarArea'之類的東西,它們不再工作了。 Qt6中這個功能有什么替代品嗎?
Qt 模塊僅存在於 PyQt5(不在 Qt5 中)中,該模塊允許訪問任何 class 或任何子模塊的元素,例如:
$ python
>>> from PyQt5 import Qt
>>> from PyQt5 import QtWidgets
>>> assert Qt.QWidget == QtWidgets.QWidget
該模塊不同於屬於 QtCore 模塊的 Qt 命名空間,因此如果要訪問 Qt.AlignCenter 則必須從 QtCore 導入 Qt:
import sys
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QLabel
def main():
app = QApplication(sys.argv)
w = QLabel()
w.resize(640, 498)
w.setAlignment(Qt.Alignment.AlignCenter)
w.setText("Qt is awesome!!!")
w.show()
app.exec()
if __name__ == "__main__":
main()
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication, QMainWindow, QStyle, QToolBar
def main():
import sys
app = QApplication(sys.argv)
toolbar = QToolBar()
toolbar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
icon = app.style().standardIcon(QStyle.StandardPixmap.SP_DesktopIcon)
toolbar.addAction(icon, "desktop")
w = QMainWindow()
w.addToolBar(Qt.ToolBarAreas.LeftToolBarArea, toolbar)
w.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()
目前, AlignCenter
和其他可以在AlignmentFlag枚舉下找到:
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QPushButton, QVBoxLayout
def create_widget():
layout = QVBoxLayout()
button = QPushButton('Cancel')
layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(button)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.