当前位置: 首页>>代码示例>>Python>>正文


Python QTableWidget.setColumnCount方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QTableWidget.setColumnCount方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidget.setColumnCount方法的具体用法?Python QTableWidget.setColumnCount怎么用?Python QTableWidget.setColumnCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QTableWidget的用法示例。


在下文中一共展示了QTableWidget.setColumnCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initUI

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
    def initUI(self):
        self.setWindowTitle("QTableWidget 例子")
        self.resize(530,300);
        conLayout = QHBoxLayout()
        tableWidget=QTableWidget()
        tableWidget.setRowCount(4)
        tableWidget.setColumnCount(3)
        conLayout.addWidget(tableWidget )
        
        tableWidget.setHorizontalHeaderLabels(['姓名','性别','体重(kg)'])  
          
        newItem = QTableWidgetItem("张三")  
        tableWidget.setItem(0, 0, newItem)  
        
        #将第1列的单元格,设置成150宽度
        tableWidget.setColumnWidth(0,150)  
        #将第1行的单元格,设置成120的高度
        tableWidget.setRowHeight(0,120)      

        newItem = QTableWidgetItem("男")  
        tableWidget.setItem(0, 1, newItem)  
          
        newItem = QTableWidgetItem("160")  
        tableWidget.setItem(0, 2, newItem)   
        
        self.setLayout(conLayout)
开发者ID:kiorry,项目名称:PYQT,代码行数:28,代码来源:qt05_tblRow.py

示例2: ParseStepViewer

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
class ParseStepViewer(QDialog):
    def __init__(self, parent, steps):
        super(ParseStepViewer, self).__init__(parent)
        self.setModal(True)
        self.setWindowTitle('Parse steps view.')
        self.resize(640, 480)

        layout = QVBoxLayout(self)
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setRowCount(len(steps))
        self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)

        self.table.setHorizontalHeaderLabels(['Stack', 'Input'])

        for row, (right, left) in enumerate(steps):
            self.table.setItem(row, 0, QTableWidgetItem('$' + ''.join(left)))
            self.table.setItem(row, 1, QTableWidgetItem(''.join(right) + '$'))

        self.table.resizeColumnsToContents()

        ok_btn = QPushButton('&Close')
        ok_btn.clicked.connect(self.close)

        layout.addWidget(self.table)
        layout.addWidget(ok_btn)
开发者ID:JPTIZ,项目名称:lfc-t2,代码行数:29,代码来源:viewers.py

示例3: skipped_gs

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
			def skipped_gs(s_list):
				"Skipped galleries"
				msg_box = QMessageBox(self)
				msg_box.setIcon(QMessageBox.Question)
				msg_box.setText('Do you want to view skipped paths?')
				msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
				msg_box.setDefaultButton(QMessageBox.No)
				if msg_box.exec() == QMessageBox.Yes:
					list_wid = QTableWidget(self)
					list_wid.setAttribute(Qt.WA_DeleteOnClose)
					list_wid.setRowCount(len(s_list))
					list_wid.setColumnCount(2)
					list_wid.setAlternatingRowColors(True)
					list_wid.setEditTriggers(list_wid.NoEditTriggers)
					list_wid.setHorizontalHeaderLabels(['Reason', 'Path'])
					list_wid.setSelectionBehavior(list_wid.SelectRows)
					list_wid.setSelectionMode(list_wid.SingleSelection)
					list_wid.setSortingEnabled(True)
					list_wid.verticalHeader().hide()
					list_wid.setAutoScroll(False)
					for x, g in enumerate(s_list):
						list_wid.setItem(x, 0, QTableWidgetItem(g[1]))
						list_wid.setItem(x, 1, QTableWidgetItem(g[0]))
					list_wid.resizeColumnsToContents()
					list_wid.setWindowTitle('{} skipped paths'.format(len(s_list)))
					list_wid.setWindowFlags(Qt.Window)
					list_wid.resize(900,400)

					list_wid.doubleClicked.connect(lambda i: utils.open_path(
						list_wid.item(i.row(), 1).text(), list_wid.item(i.row(), 1).text()))

					list_wid.show()
开发者ID:darmstard,项目名称:happypanda,代码行数:34,代码来源:app.py

示例4: MyTableWidget

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
class MyTableWidget(QWidget):

    def __init__(self):
        super().__init__()

        # Create a table
        self.tableWidget = QTableWidget()
        self.tableWidget.setRowCount(4)
        self.tableWidget.setColumnCount(2)

        # Add data
        self.tableWidget.setItem(0, 0, QTableWidgetItem("Cell (1,1)"))
        self.tableWidget.setItem(0, 1, QTableWidgetItem("Cell (1,2)"))
        self.tableWidget.setItem(1, 0, QTableWidgetItem("Cell (2,1)"))
        self.tableWidget.setItem(1, 1, QTableWidgetItem("Cell (2,2)"))
        self.tableWidget.setItem(2, 0, QTableWidgetItem("Cell (3,1)"))
        self.tableWidget.setItem(2, 1, QTableWidgetItem("Cell (3,2)"))
        self.tableWidget.setItem(3, 0, QTableWidgetItem("Cell (4,1)"))
        self.tableWidget.setItem(3, 1, QTableWidgetItem("Cell (4,2)"))

        # Table selection callback
        self.tableWidget.doubleClicked.connect(self.on_click)

        # Set the layout
        layout = QVBoxLayout()
        layout.addWidget(self.tableWidget)
        self.setLayout(layout)

    @pyqtSlot()
    def on_click(self):
        for currentQTableWidgetItem in self.tableWidget.selectedItems():
            print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())
开发者ID:jeremiedecock,项目名称:snippets,代码行数:34,代码来源:widget_QTableWidget.py

示例5: initUI

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
	def initUI(self):
		self.setWindowTitle("QTableWidget 例子")
		self.resize(430,300);
		conLayout = QHBoxLayout()
		tableWidget = QTableWidget()
		tableWidget.setRowCount(4)
		tableWidget.setColumnCount(3)
		conLayout.addWidget(tableWidget )
		
		tableWidget.setHorizontalHeaderLabels(['姓名','性别','体重(kg)'])  
		  
		newItem = QTableWidgetItem("张三")  
		tableWidget.setItem(0, 0, newItem)  
		  
		comBox = QComboBox()
		comBox.addItem("男")
		comBox.addItem("女")
		comBox.setStyleSheet("QComboBox{margin:3px};")
		tableWidget.setCellWidget(0,1,comBox)
		
		searchBtn = QPushButton("修改")  
		searchBtn.setDown( True )
		searchBtn.setStyleSheet("QPushButton{margin:3px};")
		tableWidget.setCellWidget(0, 2, searchBtn) 
		 				
		self.setLayout(conLayout)
开发者ID:kiorry,项目名称:PYQT,代码行数:28,代码来源:qt05_tblCmb.py

示例6: ParseTableViewer

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
class ParseTableViewer(QDialog):
    def __init__(self, parent, grammar):
        super(QDialog, self).__init__(parent)
        self.setModal(True)
        self.setWindowTitle('LL(1) Parsing Table')
        self.resize(640, 480)

        layout = QVBoxLayout(self)

        self.table = QTableWidget()

        def build_table():
            parse = build_parse_table(grammar)

            states = [grammar.initial_symbol] + sorted(grammar.nonterminals - {grammar.initial_symbol})

            symbols = sorted(grammar.terminals) + ['$']

            self.table.setRowCount(len(states))
            self.table.setColumnCount(len(symbols) + 1)

            self.table.setHorizontalHeaderLabels(['NT'] + symbols)
            self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)

            for row, state in enumerate(states):
                self.table.setItem(row, 0, QTableWidgetItem(state))

            for (state, symbol) in parse:
                self.table.setItem(states.index(state),
                                   symbols.index(symbol) + 1,
                                   QTableWidgetItem(f'{parse[(state, symbol)]}'))

        build_table()
        layout.addWidget(self.table)
开发者ID:JPTIZ,项目名称:lfc-t2,代码行数:36,代码来源:viewers.py

示例7: create_diff_table

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
    def create_diff_table(self, diffs):
        tbl = QTableWidget()
        tbl.setRowCount(len(diffs))
        tbl.setColumnCount(3)

        tbl.setHorizontalHeaderItem(0, QTableWidgetItem('Field'))
        tbl.setHorizontalHeaderItem(1, QTableWidgetItem('Current'))
        tbl.setHorizontalHeaderItem(2, QTableWidgetItem('Previous'))

        from PyQt5.QtGui import QColor
        red = QColor()
        red.setRed(255)

        for row, diff in enumerate(diffs):
            tbl.setItem(row, 0, QTableWidgetItem(diff.field_name))
            item1 = QTableWidgetItem(to_money(diff.current_amount))
            item2 = QTableWidgetItem(to_money(diff.previous_amount))
            if self._significant_diff(diff.current_amount, diff.previous_amount):
                item1.setForeground(red)
                item2.setForeground(red)
            tbl.setItem(row, 1, item1)
            tbl.setItem(row, 2, item2)

        tbl.verticalHeader().setVisible(False)
        tbl.resizeColumnsToContents()
        ht = tbl.rowHeight(0) * (tbl.rowCount() + 1)

        tbl.setFixedSize(tbl.horizontalHeader().length() + 20, ht)
        return tbl
开发者ID:Davincier,项目名称:payrun,代码行数:31,代码来源:paydiffs_widget.py

示例8: sig_to_stems_clicked

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
    def sig_to_stems_clicked(self, row):
        signature = self.sig_to_stems_major_table.item(row, 0).text()
        print(signature)
        signature = tuple(signature.split(SEP_SIG))

        stems = sorted(self.lexicon.signatures_to_stems()[signature])
        number_of_stems_per_column = 5

        # create a master list of sublists, where each sublist contains k stems
        # k = number_of_stems_per_column
        stem_rows = list()
        stem_row = list()

        for i, stem in enumerate(stems, 1):
            stem_row.append(stem)
            if not i % number_of_stems_per_column:
                stem_rows.append(stem_row)
                stem_row = list()
        if stem_row:
            stem_rows.append(stem_row)

        # set up the minor table as table widget
        sig_to_stems_minor_table = QTableWidget()
        sig_to_stems_minor_table.horizontalHeader().hide()
        sig_to_stems_minor_table.verticalHeader().hide()
        sig_to_stems_minor_table.clear()
        sig_to_stems_minor_table.setRowCount(len(stem_rows))
        sig_to_stems_minor_table.setColumnCount(number_of_stems_per_column)

        # fill in the minor table
        for row, stem_row in enumerate(stem_rows):
            for col, stem in enumerate(stem_row):
                item = QTableWidgetItem(stem)
                sig_to_stems_minor_table.setItem(row, col, item)

        sig_to_stems_minor_table.resizeColumnsToContents()

        minor_table_title = QLabel('{} (number of stems: {})'
                                   .format(SEP_SIG.join(signature), len(stems)))

        minor_table_widget_with_title = QWidget()
        layout = QVBoxLayout()
        layout.addWidget(minor_table_title)
        layout.addWidget(sig_to_stems_minor_table)
        minor_table_widget_with_title.setLayout(layout)

        new_display = QSplitter(Qt.Horizontal)
        new_display.setHandleWidth(10)
        new_display.setChildrenCollapsible(False)

        new_display.addWidget(self.sig_to_stems_major_table)
        new_display.addWidget(minor_table_widget_with_title)
        new_display_width = self.majorDisplay.width() / 2
        new_display.setSizes(
            [new_display_width * 0.4, new_display_width * 0.6])

        self.load_main_window(major_display=new_display)
        self.status.clearMessage()
        self.status.showMessage('{} selected'.format(signature))
开发者ID:linguistica-uchicago,项目名称:lxa5,代码行数:61,代码来源:main_window.py

示例9: initUI

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
    def initUI(self):

        api_label = QLabel("Yahoo! アプリケーションID")
        api_lineedit = QLineEdit()
        api_lineedit.setEchoMode(QLineEdit.Password)
        self.api_lineedit = api_lineedit

        text_label = QLabel("解析したい日本語")
        text_textedit = QPlainTextEdit()
        text_textedit.setTabChangesFocus(True)
        self.text_textedit = text_textedit

        grid = QGridLayout()
        grid.addWidget(api_label, 0, 0)
        grid.addWidget(api_lineedit, 0, 1)
        grid.addWidget(text_label, 1, 0)
        grid.addWidget(text_textedit, 1, 1)

        go_button = QPushButton("Go")
        go_button.setAutoDefault(True) # 
        go_button.clicked.connect(self.buttonClicked)
        hbox1 = QHBoxLayout()
        hbox1.addStretch(1)
        hbox1.addWidget(go_button)
        hbox1.addStretch(1)

        result_label = QLabel("解析結果")
        result_table = QTableWidget()
        result_table.setColumnCount(4)
        result_table.setRowCount(1)
        result_table.setItem(0, 0, QTableWidgetItem("表記"))
        result_table.setItem(0, 1, QTableWidgetItem("読みがな"))
        result_table.setItem(0, 2, QTableWidgetItem("基本形表記"))
        result_table.setItem(0, 3, QTableWidgetItem("品詞"))
        self.result_table = result_table
        hbox2 = QHBoxLayout()
        hbox2.addWidget(result_label)
        hbox2.addWidget(result_table)

        vbox = QVBoxLayout()
        vbox.addLayout(grid)
        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)

        self.setLayout(vbox)

        self.setGeometry(100, 100, 700, 550)
        self.setWindowTitle('Yahoo! 形態素解析のデモ')
        self.show()
开发者ID:minus9d,项目名称:python_exercise,代码行数:51,代码来源:yahoo_morphological_analysis.py

示例10: __init__

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
    def __init__(self, layer, parent=None):
        super(LayerColortableDialog, self).__init__(parent=parent)

        h = QHBoxLayout(self)
        t = QTableWidget(self)
        t.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        t.setRowCount(len(layer._colorTable))
        t.setColumnCount(1)
        t.setVerticalHeaderLabels(["%d" % i for i in range(len(layer._colorTable))])

        for i in range(len(layer._colorTable)):
            item = QTableWidgetItem(" ")
            t.setItem(i, 0, item)
            item.setBackgroundColor(QColor.fromRgba(layer._colorTable[i]))
            item.setFlags(Qt.ItemIsSelectable)

        h.addWidget(t)
开发者ID:ilastik,项目名称:volumina,代码行数:19,代码来源:layercontextmenu.py

示例11: initUI

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
  def initUI(self):
      self.setWindowTitle("QTableWidget 例子")
      self.resize(430, 230);
      conLayout = QHBoxLayout()
      tableWidget=QTableWidget()
      tableWidget.setRowCount(4)
      tableWidget.setColumnCount(3)
      conLayout.addWidget(tableWidget )
      
      tableWidget.setHorizontalHeaderLabels(['姓名','性别','体重(kg)'])  
        
      newItem = QTableWidgetItem("张三")  
      tableWidget.setItem(0, 0, newItem)  
               
      newItem = QTableWidgetItem("男")  
      tableWidget.setItem(0, 1, newItem)  
        
      newItem = QTableWidgetItem("160") 
      tableWidget.setItem(0, 2, newItem)   
    
      newItem = QTableWidgetItem("李四")  
      tableWidget.setItem(1, 0, newItem)  
               
      newItem = QTableWidgetItem("女")  
      tableWidget.setItem(1, 1, newItem)  
        
      newItem = QTableWidgetItem("155") 
      tableWidget.setItem(1, 2, newItem)      
     
      newItem = QTableWidgetItem("王五")  
      tableWidget.setItem(2, 0, newItem)  
               
      newItem = QTableWidgetItem("男")  
      tableWidget.setItem(2, 1, newItem)  
        
      newItem = QTableWidgetItem("170") 
      tableWidget.setItem(2, 2, newItem)        
      
 
      # Qt.DescendingOrder 降序
      # Qt.AscendingOrder 升序
      tableWidget.sortItems(2,  Qt.DescendingOrder )
      
      self.setLayout(conLayout)
开发者ID:kiorry,项目名称:PYQT,代码行数:46,代码来源:qt05_tblItemOrder.py

示例12: MyWidget

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
class MyWidget(QWidget):

    def __init__(self):
        super(QWidget, self).__init__()
        self.title = 'PyQt5 table example'
        self.left = 100
        self.top = 100
        self.width = 640
        self.height = 480
        self.__init_ui()

    def __init_ui(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        self.__create_table()

        layout = QVBoxLayout()
        layout.addWidget(self.table_widget)

        self.setLayout(layout)

    def __create_table(self):
        self.table_widget = QTableWidget()
        self.table_widget.setRowCount(4)
        self.table_widget.setColumnCount(2)

        self.table_widget.setItem(0, 0, QTableWidgetItem('Cell Item (0, 0)'))
        self.table_widget.setItem(0, 1, QTableWidgetItem('Cell Item (0, 1)'))
        self.table_widget.setItem(1, 0, QTableWidgetItem('Cell Item (1, 0)'))
        self.table_widget.setItem(1, 1, QTableWidgetItem('Cell Item (1, 1)'))
        self.table_widget.setItem(2, 0, QTableWidgetItem('Cell Item (2, 0)'))
        self.table_widget.setItem(2, 1, QTableWidgetItem('Cell Item (2, 1)'))
        self.table_widget.setItem(3, 0, QTableWidgetItem('Cell Item (3, 0)'))
        self.table_widget.setItem(3, 1, QTableWidgetItem('Cell Item (3, 1)'))

        self.table_widget.doubleClicked.connect(self.on_double_click)

    def on_double_click(self):
        print('\n')
        for item in self.table_widget.selectedItems():
            print(item.row(), item.column(), item.text())
开发者ID:nnaabbcc,项目名称:exercise,代码行数:44,代码来源:09_table_test.py

示例13: jobs_view

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
class jobs_view(QWidget):

	def __init__(self):
		QWidget.__init__(self)

		self.main_vbox=QVBoxLayout()
	
		self.tab = QTableWidget()
		self.tab.resizeColumnsToContents()

		self.tab.verticalHeader().setVisible(False)

		self.create_model()

#		self.tab.cellChanged.connect(self.tab_changed)
		
		self.main_vbox.addWidget(self.tab)

		self.setLayout(self.main_vbox)
		self.show()


	def add_items(self):
		self.store.clear()
		actresses = [("n","name","done","status","target","ip","copystate","start","stop")]

		for act in actresses:
			self.store.store.append([act[0], act[1], act[2], act[3],act[4], act[5], act[6], act[7]])

	def load_data(self,jobs_list):
		self.create_model()
		for i in range(len(jobs_list)):
			tab_add(self.tab,jobs_list[i])

	def create_model(self):
		self.tab.clear()
		self.tab.setColumnCount(7)

		self.tab.setSelectionBehavior(QAbstractItemView.SelectRows)
		self.tab.setHorizontalHeaderLabels([_("n"), _("done"), _("status"), _("target"), _("ip"),_("copy state"),_("start"),_("stop")])

		self.tab.setRowCount(0)
开发者ID:roderickmackenzie,项目名称:gpvdm,代码行数:44,代码来源:jobs.py

示例14: initUI

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
	def initUI(self):
		self.setWindowTitle("QTableWidget 例子")
		self.resize(430,230);
		conLayout = QHBoxLayout()
		tableWidget = QTableWidget()
		tableWidget.setRowCount(4)
		tableWidget.setColumnCount(3)
		conLayout.addWidget(tableWidget )
		
		tableWidget.setHorizontalHeaderLabels(['姓名','性别','体重(kg)'])  
		  
		newItem = QTableWidgetItem("张三")  
		tableWidget.setItem(0, 0, newItem)  
		  
		newItem = QTableWidgetItem("男")  
		tableWidget.setItem(0, 1, newItem)  
		  
		newItem = QTableWidgetItem("160")  
		tableWidget.setItem(0, 2, newItem)   
		
		# 将表格变为禁止编辑
		#tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
		
		# 设置表格为整行选择
		#tableWidget.setSelectionBehavior( QAbstractItemView.SelectRows)

		# 将行和列的大小设为与内容相匹配
		#tableWidget.resizeColumnsToContents()
		#tableWidget.resizeRowsToContents()
		
		#表格表头的显示与隐藏
		#tableWidget.verticalHeader().setVisible(False)
		#tableWidget.horizontalHeader().setVisible(False)
		
		# 不显示表格单元格的分割线
		#tableWidget.setShowGrid(False)
        # 不显示垂直表头
		tableWidget.verticalHeader().setVisible(False)
		
		self.setLayout(conLayout)
开发者ID:kiorry,项目名称:PYQT,代码行数:42,代码来源:qt05_tblBasic.py

示例15: App

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setColumnCount [as 别名]
class App(QWidget):
    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 table'
        self.left = 0
        self.top = 0
        self.width = 300
        self.height = 200
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.createTable()
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.tableWidget)
        self.setLayout(self.layout)

        self.show()

    def createTable(self):
        self.tableWidget = QTableWidget()
        self.tableWidget.setRowCount(4)
        self.tableWidget.setColumnCount(2)
        self.tableWidget.setItem(0, 0, QTableWidgetItem('Cell (1,1)'))
        self.tableWidget.setItem(0, 1, QTableWidgetItem('Cell (1,2)'))
        self.tableWidget.setItem(1, 0, QTableWidgetItem('Cell (2,1)'))
        self.tableWidget.setItem(1, 1, QTableWidgetItem('Cell (2,2)'))
        self.tableWidget.setItem(2, 0, QTableWidgetItem('Cell (3,1)'))
        self.tableWidget.setItem(2, 1, QTableWidgetItem('Cell (3,2)'))
        self.tableWidget.setItem(3, 0, QTableWidgetItem('Cell (4,1)'))
        self.tableWidget.setItem(3, 1, QTableWidgetItem('Cell (4,2)'))
        self.tableWidget.move(0, 0)
        self.tableWidget.doubleClicked.connect(self.on_click)

    @pyqtSlot()
    def on_click(self):
        print('\n')
        for currentQTableWidgetItem in self.tableWidget.selectedItems():
            print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())
开发者ID:lxing1988,项目名称:00_LearnPython,代码行数:42,代码来源:09_pyqt5Table.py


注:本文中的PyQt5.QtWidgets.QTableWidget.setColumnCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。