UI の QGridLayout に問題があります。ここでは、ユーザーがロードしたファイルに応答する UI を作成しようとしています。初めてロードすると、ファイルの内容を反映して QGridLayout が更新され、すべて問題ありません。ただし、次にファイルがロードされたときに、グリッド内のウィジェットが削除される必要があります (これを行うには、deleteLater() を呼び出します)。起こっていることは、それらが上書きされているということです。
画像が役立つ場合があります。これは、2 つの異なるファイルを繰り返しロードした後に表示されるものです。「Transmit Messages」と「Field」のテキストに問題がないことがわかります。
私が使用しているコードは次のとおりです。エラーがここではなく、コードの他の場所にあると誰かが感じた場合は、さらに投稿できます。しかし、問題のあるロジックはここにあるようです。特に、各呼び出しで新しい QLabel を作成することに問題はありますか?
def populateTxField(self):
# First delete the old contents
rowcount = self.txGrid.rowCount()
for i in range(1, rowcount):
try:
# Note that these widgets are QLabel type
self.txGrid.itemAtPosition(i, 4).widget().deleteLater()
self.txGrid.itemAtPosition(i, 3).widget().deleteLater()
except AttributeError:
# If widget has already been deleted, ignore the error
pass
key = self.firstTxMessageInfo.currentText()
self.txQLabel_LineContainer = [] # store QLineEdits here
# Now add all of the widgets to the transmission QGridLayout
row = 1 # counter for adding to txGrid row
for field in self.dataBack.messages[key].fields.keys():
newLabel = QtWidgets.QLabel() # Creating a new widget here...
newLabel.setText(field) # Is this problematic?
newLineEdit = QtWidgets.QLineEdit()
# Append to the following list to access from txActivateHandler.
self.txQLabel_LineContainer.append((newLabel, newLineEdit))
# Now update the grid with the new widgets
self.txGrid.addWidget(newLabel, row, 3)
self.txGrid.addWidget(newLineEdit, row, 4)
row += 1