0
app.exec_()コールの後に追加されたタブは、app.exec_()コールの後に別のタブを追加すると、 'をメインアプリケーションウィンドウから選択します。下の図を参照してください:)Python PYQT app windowの外側のタブ[why]
なぜですか?どのように私はそれをウィンドウの内側に移動することができますか?
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のGUI関連のコードは、プログラムのメインスレッドで実行する必要があります。コンソールを見ると 'QObject :: setParent:親を設定できません、新しい親は別のスレッドにあります 'というメッセージが表示されます。新しいタブは、 'md'を親として設定することができないため、デタッチされます。なぜこれがクラッシュせずに実行されるのかわからない – user3419537