[英]PyQt5 Custom Widget Opens in Another Window
我最近開始使用 PyQt5。 我想創建一個自定義小部件,然后將其插入到應用程序的主 window 中。
自定義小部件:
class ScoreCard(QtWidgets.QWidget):
def __init__(self, parent=None):
super(ScoreCard, self).__init__(parent=parent)
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint)
self.pressing = False
self.init_ui()
self.show()
def init_ui(self):
# Layout in here
這是主要的應用程序:
from PyQt5.QtWidgets import *
from scorecard import ScoreCard
import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUi()
self.show()
def initUi(self):
self.setGeometry(300,300,800,700)
window_layout = QVBoxLayout()
recent_playcard = ScoreCard()
window_layout.addWidget(recent_playcard)
self.setLayout(window_layout)
if __name__ == "__main__":
app = QApplication(sys.argv)
execute = MainWindow()
sys.exit(app.exec_())
為什么每當我運行主應用程序時,自定義小部件都會出現在另一個 window 中? 我什至嘗試刪除框架並將父級設置為無,但這些都沒有改變這種行為。 我該如何解決?
看起來我混合了QMainWindow
和QDialog
我應該為主應用程序使用中央小部件而不是設置布局..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.