最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PyQt5實現(xiàn)tableWidget 居中顯示

 更新時間:2022年07月12日 11:32:11   作者:shiyue41  
這篇文章主要介紹了PyQt5實現(xiàn)tableWidget 居中顯示方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

PyQt5 tableWidget 居中顯示

newItem = QTableWidgetItem("內(nèi)容")
# 居中顯示
newItem.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)

PyQt5 TableWidGet問題

使用pyqt5展示excel的數(shù)據(jù)到桌面,并獲取選中的數(shù)據(jù)內(nèi)容

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import pandas as pd
import numpy as np

class Ui_MainWindow(QMainWindow):
    def __init__(self):
        super(QtWidgets.QMainWindow, self).__init__()
        self.setupUi(self)
        self.retranslateUi(self)

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(666, 488)
        self.centralWidget = QtWidgets.QWidget(MainWindow)
        self.centralWidget.setObjectName("centralWidget")
        self.retranslateUi(MainWindow)
        self.tableWidget = QtWidgets.QTableWidget(self.centralWidget)
        self.tableWidget.setGeometry(QtCore.QRect(0, 60, 813, 371))
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(0)
        self.tableWidget.setRowCount(0)
        self.tableWidget.setStyleSheet("selection-background-color:pink")
        self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.tableWidget.setSelectionBehavior(QTableWidget.SelectRows)
        self.tableWidget.raise_()
        # 設置圖標

        self.pushButton = QtWidgets.QPushButton(self.centralWidget)
        self.pushButton.setGeometry(QtCore.QRect(90, 20, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton.setText("打開")
        MainWindow.setCentralWidget(self.centralWidget)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        self.pushButton.clicked.connect(self.openfile)
        self.pushButton.clicked.connect(self.creat_table_show)
        # 確定
        self.okButton = QtWidgets.QPushButton(self.centralWidget)
        self.okButton.setGeometry(QtCore.QRect(180, 20, 75, 23))
        self.okButton.setObjectName("okButton")
        self.okButton.setText("確定")
        MainWindow.setCentralWidget(self.centralWidget)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        self.okButton.clicked.connect(self.get_select)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "測試數(shù)據(jù)"))
        MainWindow.setWindowIcon(QIcon("./head.jpg"))
        # MainWindow.show()

    def get_select(self):
        # print(self.tableWidget.columnCount()) # 返回列數(shù)
        # print(self.tableWidget.rowCount())  # 返回行數(shù)
        colomn = self.tableWidget.columnCount()
        row_list = set()
        for i in self.tableWidget.selectionModel().selection().indexes():
            row_list.add(i.row())
        # print(row_list)
        select_data = []
        for row in row_list:
            row_data = [self.tableWidget.item(row, p).text() for p in range(colomn)]
            select_data.append(row_data)
        print(select_data)

    def openfile(self):
        # 獲取路徑
        openfile_name = QFileDialog.getOpenFileName(self, '選擇文件', '', 'Excel files(*.xlsx , *.xls)')
        #print(openfile_name)
        global path_openfile_name
        path_openfile_name = openfile_name[0]

    def creat_table_show(self):
        # 讀取表格,轉(zhuǎn)換表格
        if len(path_openfile_name) > 0:
            input_table = pd.read_excel(path_openfile_name)
            # print(1,input_table)
            input_table_rows = input_table.shape[0]
            input_table_colunms = input_table.shape[1]
            # print(2,input_table_rows)
            # print(3,input_table_colunms)
            input_table_header = input_table.columns.values.tolist()
            #print(input_table_header)
            #讀取表格,轉(zhuǎn)換表格,給tablewidget設置行列表頭
            self.tableWidget.setColumnCount(input_table_colunms)
            self.tableWidget.setRowCount(input_table_rows)
            self.tableWidget.setHorizontalHeaderLabels(input_table_header)
            #給tablewidget設置行列表頭
            #遍歷表格每個元素,同時添加到tablewidget中
            for i in range(input_table_rows):
                input_table_rows_values = input_table.iloc[[i]]
                #print(input_table_rows_values)
                input_table_rows_values_array = np.array(input_table_rows_values)
                input_table_rows_values_list = input_table_rows_values_array.tolist()[0]
                 #print(input_table_rows_values_list)
                for j in range(input_table_colunms):
                    input_table_items_list = input_table_rows_values_list[j]
                    #print(input_table_items_list)
                    # print(type(input_table_items_list))
                    #將遍歷的元素添加到tablewidget中并顯示
                    input_table_items = str(input_table_items_list)
                    newItem = QTableWidgetItem(input_table_items)
                    newItem.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
                    self.tableWidget.setItem(i, j, newItem)
        #遍歷表格每個元素,同時添加到tablewidget中
        else:
            self.centralWidget.show()
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • Python api構建tensorrt加速模型的步驟詳解

    Python api構建tensorrt加速模型的步驟詳解

    小編個人認為python比c++更容易讀并且已經(jīng)有很多包裝很好的科學運算庫(numpy,scikit等),今天通過本文給大家分享Python api構建tensorrt加速模型的步驟,感興趣的朋友一起看看吧
    2021-09-09
  • Python報錯ModuleNotFoundError: No module named ‘tensorboard‘的解決方法

    Python報錯ModuleNotFoundError: No module named&

    在嘗試導入TensorBoard模塊時,你可能會遇到ModuleNotFoundError: No module named 'tensorboard'的錯誤,下面我們來分析這個問題并提供解決方案,需要的朋友可以參考下
    2024-09-09
  • 詳解Python3.1版本帶來的核心變化

    詳解Python3.1版本帶來的核心變化

    這篇文章主要介紹了詳解Python3.1版本帶來的核心變化,Python3.1的版本升級在3.0的基礎上帶來了更多影響以后版本的變化,本文分析了其中一些常用功能的改變,如Maketrans函數(shù)等,需要的朋友可以參考下
    2015-04-04
  • opencv 分類白天與夜景視頻的方法

    opencv 分類白天與夜景視頻的方法

    最近有個數(shù)據(jù)需要分類處理,是一批含有白天跟夜晚的視頻數(shù)據(jù),需要進行區(qū)分開來,本文就來實現(xiàn),感興趣的可以了解一下
    2021-06-06
  • Python Cookie 讀取和保存方法

    Python Cookie 讀取和保存方法

    今天小編就為大家分享一篇Python Cookie 讀取和保存方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • python?kornia計算機視覺庫實現(xiàn)圖像變化

    python?kornia計算機視覺庫實現(xiàn)圖像變化

    這篇文章主要為大家介紹了python?kornia計算機視覺庫實現(xiàn)圖像變化算法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2024-01-01
  • 使用Python生成隨機圖片驗證碼的代碼詳解

    使用Python生成隨機圖片驗證碼的代碼詳解

    當我們在寫一個Web項目的時候一般要寫登錄操作,而為了安全起見,現(xiàn)在的登錄功能都會加上輸入圖片驗證碼這一功能,所以本文就給大家介紹一下如何使用Python生成隨機圖片驗證碼,需要的朋友可以參考下
    2023-07-07
  • Flask中特殊裝飾器的使用

    Flask中特殊裝飾器的使用

    本文主要介紹了Flask中特殊裝飾器的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-02-02
  • Python判斷對象是否為文件對象(file object)的三種方法示例

    Python判斷對象是否為文件對象(file object)的三種方法示例

    這篇文章主要介紹了Python判斷對象是否為文件對象(file object)的三種方法示例,https://www.pythontab.com/html/2018/pythonhexinbiancheng_1015/1362.html
    2019-04-04
  • python去除列表中的空值元素實戰(zhàn)技巧

    python去除列表中的空值元素實戰(zhàn)技巧

    這篇文章主要介紹了python實戰(zhàn)技巧之去除列表中的空值元素,搜集針對python高效處理數(shù)據(jù)的核心代碼,今天是實現(xiàn)去除列表中的空值元素,需要的朋友可以參考下
    2023-02-02

最新評論

托里县| 洛川县| 东阳市| 内丘县| 阳谷县| 临湘市| 鹤庆县| 西贡区| 乌拉特中旗| 嵊泗县| 封开县| 彭山县| 廉江市| 岳阳市| 宁远县| 建宁县| 光山县| 芜湖县| 金华市| 泊头市| 灵寿县| 江川县| 苍山县| 司法| 西盟| 略阳县| 保康县| 德惠市| 临潭县| 沧源| 沙坪坝区| 龙山县| 太仆寺旗| 宁安市| 龙胜| 金塔县| 金门县| 泽库县| 平阳县| 丹巴县| 扎鲁特旗|