我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用PySide.QtGui.QTableWidget()。
def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(573, 391) self.verticalLayout = QtGui.QVBoxLayout(Dialog) self.verticalLayout.setObjectName("verticalLayout") self.table = QtGui.QTableWidget(Dialog) self.table.setObjectName("table") self.table.setColumnCount(0) self.table.setRowCount(0) self.verticalLayout.addWidget(self.table) self.label = QtGui.QLabel(Dialog) font = QtGui.QFont() font.setPointSize(12) font.setWeight(75) font.setItalic(False) font.setBold(True) self.label.setFont(font) self.label.setFrameShape(QtGui.QFrame.NoFrame) self.label.setTextFormat(QtCore.Qt.AutoText) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setObjectName("label") self.verticalLayout.addWidget(self.label) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog)
def __init__(self, parent=None): QtGui.QTableWidget.__init__(self, parent) self.setColumnCount(9) self.setHorizontalHeaderLabels([u"", u"Parameter", "Visible", "X", "Y", "Z", "Size", "Color", "Align"]) self.setSortingEnabled(False) self.horizontalHeader().setStretchLastSection(True) self.verticalHeader().hide() self.setGridStyle(QtCore.Qt.PenStyle(QtCore.Qt.NoPen)) self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self.setStyleSheet(''' border: 1px solid #808080; ''')
def __init__(self, parent=None): QtGui.QTableWidget.__init__(self, parent) self.setColumnCount(8) self.setHorizontalHeaderLabels([u"Package name", u"Software", "X", "Y", "Z", "RX", "RY", "RZ"]) self.setSortingEnabled(False) self.horizontalHeader().setStretchLastSection(True) self.verticalHeader().hide() self.setGridStyle(QtCore.Qt.PenStyle(QtCore.Qt.DashLine)) self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) self.setStyleSheet(''' border: 1px solid #808080; ''')
def __init__(self, parent=None): QtGui.QTableWidget.__init__(self, parent) self.setSortingEnabled(False) #self.setGridStyle(Qt.NoPen) self.setShowGrid(False) self.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self.horizontalHeader().setStretchLastSection(True) self.verticalHeader().hide() self.setFrameShape(QtGui.QFrame.NoFrame) self.setStyleSheet(''' QTableWidget QHeaderView { border:0px; } QTableWidget { border: 1px solid #9EB6CE; border-top:0px; } QTableWidget QHeaderView::section { color:#4C4161; font-size:12px; border:1px solid #9EB6CE; border-left:0px; padding:5px 0; } ''')
def setLang(self, langName): lang_data = self.memoData['lang'][langName] for ui_name in lang_data.keys(): if ui_name in self.uiList.keys() and lang_data[ui_name] != '': ui_element = self.uiList[ui_name] # '' means no translation availdanle in that data file if isinstance(ui_element, (QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox) ): # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox ui_element.setText(lang_data[ui_name]) elif isinstance(ui_element, (QtWidgets.QGroupBox, QtWidgets.QMenu) ): # uiType: QMenu, QGroupBox ui_element.setTitle(lang_data[ui_name]) elif isinstance(ui_element, QtWidgets.QTabWidget): # uiType: QTabWidget tabCnt = ui_element.count() tabNameList = lang_data[ui_name].split(';') if len(tabNameList) == tabCnt: for i in range(tabCnt): if tabNameList[i] != '': ui_element.setTabText(i,tabNameList[i]) elif isinstance(ui_element, QtWidgets.QComboBox): # uiType: QComboBox itemCnt = ui_element.count() itemNameList = lang_data[ui_name].split(';') ui_element.clear() ui_element.addItems(itemNameList) elif isinstance(ui_element, QtWidgets.QTreeWidget): # uiType: QTreeWidget labelCnt = ui_element.headerItem().columnCount() labelList = lang_data[ui_name].split(';') ui_element.setHeaderLabels(labelList) elif isinstance(ui_element, QtWidgets.QTableWidget): # uiType: QTableWidget colCnt = ui_element.columnCount() headerList = lang_data[ui_name].split(';') cur_table.setHorizontalHeaderLabels( headerList ) elif isinstance(ui_element, (str, unicode) ): # uiType: string for msg self.uiList[ui_name] = lang_data[ui_name]
def createAssetsTab(self,*args): ###Assets TAB self.AssetsTab = QtGui.QWidget() self.AssetsTab.setObjectName("assetsTab") #Assets Layout self.AssetshorizontalLayout = QtGui.QHBoxLayout(self.AssetsTab) self.AssetshorizontalLayout.setObjectName("AssetshorizontalLayout") #AssetsTable self.AssetsTable = QtGui.QTableWidget(self.AssetsTab) self.AssetsTable.setObjectName("AssetsTable") self.AssetsTable.verticalHeader().hide() #self.AssetsTable.horizontalHeader().hide() self.AssetsTable.setColumnCount(2) item = QtGui.QTableWidgetItem() item.setText("name") self.AssetsTable.setHorizontalHeaderItem(0, item) item = QtGui.QTableWidgetItem() self.AssetsTable.setAlternatingRowColors(True) self.AssetsTable.setSortingEnabled(True) self.AssetsTable.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.AssetsTable.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) self.AssetsTable.horizontalHeader().stretchLastSection() self.AssetshorizontalLayout.addWidget(self.AssetsTable) self.getAssetData() self.bottomTab.addTab(self.AssetsTab,"assetsTab") self.tabs.append("assetsTab") self.bottomTab.setCurrentIndex(self.tabs.index("assetsTab"))
def tabCategories(self): tab = QtGui.QWidget() # buttons selectAll = QtGui.QPushButton() selectAll.setFlat(True) selectAll.setToolTip('Select all') selectAll.setIcon(QtGui.QIcon(":/data/img/checkbox_checked_16x16.png")) selectAll.setStyleSheet('''border:1px solid rgb(237, 237, 237);''') self.connect(selectAll, QtCore.SIGNAL("clicked()"), self.selectAllCategories) unselectAll = QtGui.QPushButton() unselectAll.setFlat(True) unselectAll.setToolTip('Deselect all') unselectAll.setIcon(QtGui.QIcon(":/data/img/checkbox_unchecked_16x16.PNG")) unselectAll.setStyleSheet('''border:1px solid rgb(237, 237, 237);''') self.connect(unselectAll, QtCore.SIGNAL("clicked()"), self.unselectAllCategories) # table self.categoriesTable = QtGui.QTableWidget() self.categoriesTable.setStyleSheet('''border:0px solid red;''') self.categoriesTable.setColumnCount(5) self.categoriesTable.setGridStyle(QtCore.Qt.DashDotLine) self.categoriesTable.setHorizontalHeaderLabels([' Active ', 'ID', 'Name', 'Description', 'Action']) self.categoriesTable.verticalHeader().hide() self.categoriesTable.horizontalHeader().setResizeMode(0, QtGui.QHeaderView.ResizeToContents) self.categoriesTable.horizontalHeader().setStretchLastSection(True) self.categoriesTable.hideColumn(1) # main lay layTableButtons = QtGui.QHBoxLayout() layTableButtons.addWidget(selectAll) layTableButtons.addWidget(unselectAll) layTableButtons.addStretch(10) lay = QtGui.QGridLayout(tab) lay.addLayout(layTableButtons, 0, 0, 1, 1) lay.addWidget(self.categoriesTable, 1, 0, 1, 1) lay.setRowStretch(1, 10) lay.setColumnStretch(0, 10) lay.setContentsMargins(5, 5, 5, 5) return tab
def _create_layouts_and_widgets(self): self._table_layout = QtGui.QGridLayout() self._table = QtGui.QTableWidget(0,6,self) self._table_header = QtGui.QHeaderView(QtCore.Qt.Orientation.Horizontal) self._table_header.setResizeMode(QtGui.QHeaderView.ResizeToContents) # self._table_header.stretchLastSection() self._table.setHorizontalHeader(self._table_header) self._table.setHorizontalHeaderLabels(['Savegame','Last backed up','Auto\nbackup','Upload\nbackups','Manual\nbackup','Latest URL']) self._table.itemClicked.connect(self.item_clicked_handler) self._logo = QtGui.QLabel() self._logo.setPixmap(QtGui.QPixmap("images/logo.png")) self._profile_button = QtGui.QPushButton("&My Account") self._profile_button.clicked.connect(self.open_acc_page) self._run_sdv_button = QtGui.QPushButton("Launch &Game!") self._run_sdv_button.clicked.connect(self.run_stardew_valley) self._browse_button = QtGui.QPushButton("&Backups") self._browse_button.clicked.connect(self.open_browse_backups) self._logout_button = QtGui.QPushButton("&Logout") self._logout_button.clicked.connect(self._logout) self._exit_button = QtGui.QPushButton("E&xit") self._exit_button.clicked.connect(self._icon_exit) self._help_button = QtGui.QPushButton("&Help") self._help_button.clicked.connect(self.open_help) self._update_button = QtGui.QPushButton("&Updates") self._update_button.clicked.connect(self.check_for_update) self._table_layout.addWidget(self._table) self._vbox = QtGui.QVBoxLayout() self._hbox_title = QtGui.QHBoxLayout() self._vbox_title = QtGui.QVBoxLayout() self._menubar = QtGui.QHBoxLayout() self._hbox_title.addWidget(self._logo) self._hbox_title.addStretch(1) self._hbox_title.addLayout(self._vbox_title) self._vbox_title.addLayout(self._menubar) self._vbox_title.setAlignment(QtCore.Qt.AlignTop) self._menubar.addWidget(self._profile_button) self._menubar.addWidget(self._run_sdv_button) self._menubar.addWidget(self._browse_button) self._menubar.addWidget(self._logout_button) self._menubar.addWidget(self._exit_button) self._menubar.addWidget(self._help_button) self._menubar.addWidget(self._update_button) self._vbox.addLayout(self._hbox_title) self._vbox.addLayout(self._table_layout) self._main_widget = QtGui.QWidget() self._main_widget.setLayout(self._vbox) self._main_widget.setMinimumWidth(700) self._main_widget.setMinimumHeight(500) self.setCentralWidget(self._main_widget)
def __init__(self, parent=None, mode=0): QtWidgets.QMainWindow.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version = '0.1' self.date = '2017.01.01' self.log = 'no version log in user class' self.help = 'no help guide in user class' self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.memoData['font_size_default'] = QtGui.QFont().pointSize() self.memoData['font_size'] = self.memoData['font_size_default'] self.memoData['last_export'] = '' self.memoData['last_import'] = '' self.name = self.__class__.__name__ self.location = '' if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(sys.modules[self.__class__.__module__].__file__) self.iconPath = os.path.join(os.path.dirname(self.location),'icons',self.name+'.png') self.iconPix = QtGui.QPixmap(self.iconPath) self.icon = QtGui.QIcon(self.iconPath) self.fileType='.{0}_EXT'.format(self.name) #------------------------------ # core function variable #------------------------------ self.qui_core_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txt': 'QTextEdit', 'list': 'QListWidget', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', 'menu' : 'QMenu', 'menubar' : 'QMenuBar', } self.qui_user_dict = {}
def __init__(self, parent=None, mode=0): super_class.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version = "0.1" self.date = '2017.01.01' self.log = 'no version log in user class' self.help = 'no help guide in user class' self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.memoData['font_size_default'] = QtGui.QFont().pointSize() self.memoData['font_size'] = self.memoData['font_size_default'] self.memoData['last_export'] = '' self.memoData['last_import'] = '' self.location = "" if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(sys.modules[self.__class__.__module__].__file__) self.name = self.__class__.__name__ self.iconPath = os.path.join(os.path.dirname(self.location),'icons',self.name+'.png') self.iconPix = QtGui.QPixmap(self.iconPath) self.icon = QtGui.QIcon(self.iconPath) self.fileType='.{0}_EXT'.format(self.name) #------------------------------ # core function variable #------------------------------ self.qui_core_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txt': 'QTextEdit', 'list': 'QListWidget', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', 'menu' : 'QMenu', 'menubar' : 'QMenuBar', } self.qui_user_dict = {} #------------------------------
def __init__(self, parent=None, mode=0): super_class.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version = "0.1" self.date = '2017.01.01' self.log = 'no version log in user class' self.help = 'no help guide in user class' self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.memoData['font_size_default'] = QtGui.QFont().pointSize() self.memoData['font_size'] = self.memoData['font_size_default'] self.location = "" if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(sys.modules[self.__class__.__module__].__file__) self.name = self.__class__.__name__ self.iconPath = os.path.join(os.path.dirname(self.location),'icons',self.name+'.png') self.iconPix = QtGui.QPixmap(self.iconPath) self.icon = QtGui.QIcon(self.iconPath) self.fileType='.{0}_EXT'.format(self.name) #------------------------------ # core function variable #------------------------------ self.qui_core_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txt': 'QTextEdit', 'list': 'QListWidget', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', 'menu' : 'QMenu', 'menubar' : 'QMenuBar', } self.qui_user_dict = {} #------------------------------
def setupUi(self, Form): Form.setObjectName("Form") Form.resize(1262, 529) self.user_email = QtGui.QLabel(Form) self.user_email.setGeometry(QtCore.QRect(1030, 20, 221, 31)) font = QtGui.QFont() font.setPointSize(12) font.setWeight(75) font.setBold(True) self.user_email.setFont(font) self.user_email.setObjectName("user_email") self.retrieve_button = QtGui.QPushButton(Form) self.retrieve_button.setGeometry(QtCore.QRect(10, 50, 103, 34)) self.retrieve_button.setObjectName("retrieve_button") self.compose_button = QtGui.QPushButton(Form) self.compose_button.setGeometry(QtCore.QRect(140, 50, 103, 34)) self.compose_button.setObjectName("compose_button") self.received_email = QtGui.QTableWidget(Form) self.received_email.setGeometry(QtCore.QRect(10, 90, 821, 431)) self.received_email.setObjectName("received_email") self.received_email.setColumnCount(3) self.received_email.setRowCount(0) item = QtGui.QTableWidgetItem() self.received_email.setHorizontalHeaderItem(0, item) item = QtGui.QTableWidgetItem() self.received_email.setHorizontalHeaderItem(1, item) item = QtGui.QTableWidgetItem() self.received_email.setHorizontalHeaderItem(2, item) self.email_body = QtGui.QTextBrowser(Form) self.email_body.setGeometry(QtCore.QRect(840, 120, 411, 401)) self.email_body.setObjectName("email_body") self.label = QtGui.QLabel(Form) self.label.setGeometry(QtCore.QRect(930, 80, 91, 41)) font = QtGui.QFont() font.setPointSize(12) font.setWeight(75) font.setBold(True) self.label.setFont(font) self.label.setObjectName("label") self.app_title = QtGui.QLabel(Form) self.app_title.setGeometry(QtCore.QRect(10, 0, 101, 41)) font = QtGui.QFont() font.setPointSize(18) font.setWeight(75) font.setBold(True) self.app_title.setFont(font) self.app_title.setObjectName("app_title") self.showing_label = QtGui.QLabel(Form) self.showing_label.setGeometry(QtCore.QRect(560, 60, 271, 20)) font = QtGui.QFont() font.setPointSize(12) font.setWeight(75) font.setBold(True) self.showing_label.setFont(font) self.showing_label.setObjectName("showing_label") self.open_browser = QtGui.QPushButton(Form) self.open_browser.setGeometry(QtCore.QRect(1100, 80, 151, 34)) self.open_browser.setObjectName("open_browser") self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)