0
标签app.exec_前加入()以外的Python PyQt的标签被称为外观和行为为u满足任何其他选项卡,但如果app.exec_()调用之后添加另一个使得新选项卡“分离'从主应用程序窗口。 PIC下面:)应用程序窗口[为什么]
为什么?我怎样才能让它在窗户内移动?
import threading
import time
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QFormLayout
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QTabWidget
from PyQt5.QtWidgets import QTextEdit
from PyQt5.QtWidgets import QWidget
class ATry(threading.Thread):
def __init__(self):
super().__init__()
def run(self):
time.sleep(1)
anotherTextEdit = QTextEdit()
anotherLineEdit = QLineEdit()
anotherLayout = QFormLayout()
anotherLayout.addRow(anotherTextEdit)
anotherLayout.addRow(anotherLineEdit)
anotherTab = QWidget()
anotherTab.setLayout(anotherLayout)
md.addTab(anotherTab, "Outside")
app = QApplication(sys.argv)
md = QTabWidget()
aTextEdit = QTextEdit()
aLineEdit = QLineEdit()
layout = QFormLayout()
layout.addRow(aTextEdit)
layout.addRow(aLineEdit)
thisTab = QWidget()
thisTab.setLayout(layout)
md.addTab(thisTab, "Inside")
a = ATry()
a.start()
md.show()
app.exec_()
所有Qt的图形用户界面相关的代码必须在程序的主线程中运行。如果你看一下在控制台上,你会看到一条消息'的QObject ::的setParent:无法设置父,新的父是在不同的thread'。新选项卡被分离,因为'md'不能被设置为父级。为什么这个运行没有崩溃我不知道 – user3419537