单击按钮时,我想从 QTableView 获取活动的 QRadioButton 。但我不知道该怎么做。
假设我有一个 csv 文件my_csv包含
ANIMAL; AGE
DOG; 3
CAT; 5
COW; 5
这是我的示例代码:
import pandas as pd
from PySide2.QtCore import Qt
from PySide2.QtGui import QStandardItemModel, QStandardItem
from PySide2.QtWidgets import QApplication, QTableView, QRadioButton, QPushButton
my_button = QPushButton()
model = QStandardItemModel()
view = QTableView()
view.setModel(model)
df = pd.read_csv(my_csv, sep=';')
header = list(['']) + df.columns
model.setHorizontalHeaderLabels(header)
for index in df_interface.index:
data = list()
item = QStandardItem()
data.append(item)
items = [QStandardItem("{}".format(field)) for field in df.iloc[index]]
[element.setTextAlignment(Qt.AlignVCenter | Qt.AlignHCenter) for element in items]
data.extend(items)
model.appendRow(data)
view.setIndexWidget(self.model.index(index, 0), QRadioButton())