我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用PyQt5.QtWidgets.QTableView()。
def setupUi(self, Form): Form.setObjectName("Form") self.gridLayout = QtWidgets.QGridLayout(Form) self.gridLayout.setObjectName("gridLayout") self.chooseDataLabel = QtWidgets.QLabel(Form) self.chooseDataLabel.setObjectName("chooseDataLabel") self.gridLayout.addWidget(self.chooseDataLabel, 0, 0, 1, 1) self.chooseDataComboBox = QtWidgets.QComboBox(Form) self.chooseDataComboBox.setObjectName("chooseDataComboBox") self.gridLayout.addWidget(self.chooseDataComboBox, 0, 1, 1, 1) self.refreshTablePushButton = QtWidgets.QPushButton(Form) self.refreshTablePushButton.setObjectName("refreshTablePushButton") self.gridLayout.addWidget(self.refreshTablePushButton, 2, 1, 1, 1) self.tableView = QtWidgets.QTableView(Form) self.tableView.setObjectName("tableView") self.gridLayout.addWidget(self.tableView, 4, 0, 1, 2) self.refreshDataPushButton = QtWidgets.QPushButton(Form) self.refreshDataPushButton.setObjectName("refreshDataPushButton") self.gridLayout.addWidget(self.refreshDataPushButton, 1, 1, 1, 1) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def __init__(self): super(TableView, self).__init__() # self.clicked.connect(self.show_cell) self.setStyleSheet(""" QTableView { background-color: #646464; padding: 4px; font-size: 8pt; border-style: none; border-bottom: 1px solid #fffff8; border-right: 1px solid #fffff8; selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0.5, y2: 0.5, stop: 0 #FF92BB, stop: 1 white); } """)
def __init__(self, parent=None): super().__init__(parent) self.horizontalHeader().setVisible(False) self.verticalHeader().setVisible(False) self.verticalHeader().setDefaultSectionSize(16) self.horizontalHeader().setDefaultSectionSize(23) self.setStyleSheet("QTableView {background-color: transparent;}") self.setShowGrid(False) self.setSelectionMode(QAbstractItemView.SingleSelection) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setAutoScroll(False)
def get_table_by_name(self, name): return self.get_main_window().findChild(QtWidgets.QTableView, name)
def get_selected_rows(self): table = self.get_current_table() assert isinstance(table, QTableView) sel_model = table.selectionModel() assert isinstance(sel_model, QItemSelectionModel) indexes = sel_model.selectedRows() ret = [] for i in indexes: assert isinstance(i, QModelIndex) orig_index_int = i.row() ret.append(orig_index_int) return ret
def accept(self): try: # apply filter here if self.table is not None: assert (isinstance(self.table, QTableView)) proxy_model = self.table.model() proxy_model.clear_filter() group_column = 4 team_column = 5 if GlobalAccess().get_current_tab_index() == 1: group_column = 2 team_column = 3 proxy_model.set_filter_for_column(group_column, self.group_combo.currentText()) proxy_model.set_filter_for_column(team_column, self.team_combo.currentText()) proxy_model.apply_filter() GlobalAccess().get_main_window().refresh() except Exception as e: logging.exception(str(e)) self.destroy()
def createView(title, model): view = QTableView() view.setModel(model) view.setItemDelegate(QSqlRelationalDelegate(view)) view.setWindowTitle(title) return view
def createView(title, model): global offset, views view = QTableView() views.append(view) view.setModel(model) view.setWindowTitle(title) view.move(100 + offset, 100 + offset) offset += 20 view.show()
def createView(title, model): view = QTableView() view.setModel(model) view.setWindowTitle(title) return view
def init_widget(self): self.setWindowTitle("QComboBox Widget") self.setMinimumWidth(350) form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent=self) self.setLayout(form_lbx) data = [ {"name": "Apple", "image": IMAGE_PATH + "apple.jpg", "color": "Red"}, {"name": "Banana", "image": IMAGE_PATH + "banana.jpg", "color": "Yellow"} ] model = UserModel(data) qb = QComboBox() view = QTableView() view.setSelectionBehavior(view.SelectRows) # ? ? ??? ?? qb.setView(view) qb.setModel(model) form_lbx.addWidget(qb)
def setUp(self): self.server = Server() self.server.set_endpoint("opc.tcp://0.0.0.0:48409/freeopcua/server/") self.server.start() self.widget = RefsWidget(QTableView())
def setupUi(self, logfileDialog): logfileDialog.setObjectName("logfileDialog") logfileDialog.resize(640, 480) self.verticalLayout = QtWidgets.QVBoxLayout(logfileDialog) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setSpacing(10) self.verticalLayout.setObjectName("verticalLayout") self.scrollArea = QtWidgets.QScrollArea(logfileDialog) self.scrollArea.setFrameShape(QtWidgets.QFrame.NoFrame) self.scrollArea.setWidgetResizable(True) self.scrollArea.setObjectName("scrollArea") self.scrollAreaWidgetContents = QtWidgets.QWidget() self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 640, 480)) self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents) self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.verticalLayout_2.setObjectName("verticalLayout_2") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.label = QtWidgets.QLabel(self.scrollAreaWidgetContents) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) self.label.setSizePolicy(sizePolicy) self.label.setObjectName("label") self.horizontalLayout.addWidget(self.label) self.check_errors = QtWidgets.QCheckBox(self.scrollAreaWidgetContents) self.check_errors.setObjectName("check_errors") self.horizontalLayout.addWidget(self.check_errors) self.check_warnings = QtWidgets.QCheckBox(self.scrollAreaWidgetContents) self.check_warnings.setObjectName("check_warnings") self.horizontalLayout.addWidget(self.check_warnings) self.check_info = QtWidgets.QCheckBox(self.scrollAreaWidgetContents) self.check_info.setObjectName("check_info") self.horizontalLayout.addWidget(self.check_info) spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.verticalLayout_2.addLayout(self.horizontalLayout) self.log_table = QtWidgets.QTableView(self.scrollAreaWidgetContents) self.log_table.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel) self.log_table.setObjectName("log_table") self.log_table.horizontalHeader().setStretchLastSection(True) self.log_table.verticalHeader().setVisible(False) self.verticalLayout_2.addWidget(self.log_table) self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.verticalLayout.addWidget(self.scrollArea) self.retranslateUi(logfileDialog) QtCore.QMetaObject.connectSlotsByName(logfileDialog)
def split_printout_selected(self): if self.current_tab != 1: logging.warning(_('No result selected')) return try: obj = race() table = GlobalAccess().get_result_table() assert isinstance(table, QTableView) index = table.currentIndex().row() if index < 0: index = 0 if index >= len(obj.results): mes = QMessageBox() mes.setText(_('No results to print')) mes.exec() return self.split_printout(obj.results[index]) except Exception as e: logging.exception(str(e))
def setupUi(self, DialogMessageType): DialogMessageType.setObjectName("DialogMessageType") DialogMessageType.resize(471, 359) self.gridLayout = QtWidgets.QGridLayout(DialogMessageType) self.gridLayout.setObjectName("gridLayout") self.rbAssignManually = QtWidgets.QRadioButton(DialogMessageType) self.rbAssignManually.setObjectName("rbAssignManually") self.gridLayout.addWidget(self.rbAssignManually, 0, 0, 1, 1) self.rbAssignAutomatically = QtWidgets.QRadioButton(DialogMessageType) self.rbAssignAutomatically.setObjectName("rbAssignAutomatically") self.gridLayout.addWidget(self.rbAssignAutomatically, 0, 1, 1, 1) self.cbRulesetMode = QtWidgets.QComboBox(DialogMessageType) self.cbRulesetMode.setObjectName("cbRulesetMode") self.cbRulesetMode.addItem("") self.cbRulesetMode.addItem("") self.cbRulesetMode.addItem("") self.gridLayout.addWidget(self.cbRulesetMode, 1, 0, 1, 2) self.tblViewRuleset = QtWidgets.QTableView(DialogMessageType) self.tblViewRuleset.setObjectName("tblViewRuleset") self.gridLayout.addWidget(self.tblViewRuleset, 2, 0, 3, 2) self.btnAddRule = QtWidgets.QToolButton(DialogMessageType) icon = QtGui.QIcon.fromTheme("list-add") self.btnAddRule.setIcon(icon) self.btnAddRule.setObjectName("btnAddRule") self.gridLayout.addWidget(self.btnAddRule, 2, 2, 1, 1) self.btnRemoveRule = QtWidgets.QToolButton(DialogMessageType) icon = QtGui.QIcon.fromTheme("list-remove") self.btnRemoveRule.setIcon(icon) self.btnRemoveRule.setObjectName("btnRemoveRule") self.gridLayout.addWidget(self.btnRemoveRule, 3, 2, 1, 1) spacerItem = QtWidgets.QSpacerItem(20, 145, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.gridLayout.addItem(spacerItem, 4, 2, 1, 1) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.btnSaveAndApply = QtWidgets.QPushButton(DialogMessageType) self.btnSaveAndApply.setObjectName("btnSaveAndApply") self.horizontalLayout.addWidget(self.btnSaveAndApply) self.btnClose = QtWidgets.QPushButton(DialogMessageType) self.btnClose.setObjectName("btnClose") self.horizontalLayout.addWidget(self.btnClose) self.gridLayout.addLayout(self.horizontalLayout, 5, 0, 1, 2) self.retranslateUi(DialogMessageType) QtCore.QMetaObject.connectSlotsByName(DialogMessageType)