Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何验证qtable小部件不是空的_Python 3.x_Pyqt5 - Fatal编程技术网

Python 3.x 如何验证qtable小部件不是空的

Python 3.x 如何验证qtable小部件不是空的,python-3.x,pyqt5,Python 3.x,Pyqt5,假设我有一个QTableWidgetItem和按钮来获取矩阵值。我想确保在单击submit(提交)按钮时,整个矩阵单元格都填充了值。这样我可以进一步计算值。它应该向用户发送一条消息,表明他填写了该项目。也不运行任何东西 我还搜索cellEntered()cellChanged()方法。我不知道如何确保用户在提交之前在所有单元格中输入数据 如何为该QTableWidgetItem项目使用验证器 from PyQt5 import QtCore, QtGui, QtWidgets from PyQt

假设我有一个QTableWidgetItem和按钮来获取矩阵值。我想确保在单击submit(提交)按钮时,整个矩阵单元格都填充了值。这样我可以进一步计算值。它应该向用户发送一条消息,表明他填写了该项目。也不运行任何东西

我还搜索cellEntered()cellChanged()方法。我不知道如何确保用户在提交之前在所有单元格中输入数据

如何为该QTableWidgetItem项目使用验证器

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QTableWidget, QApplication, QMainWindow, QTableWidgetItem, QFileDialog,qApp, QAction,QStyledItemDelegate,QLineEdit
from pandas import DataFrame
from numpy.linalg import inv
from PyQt5.QtCore import QRegExp
from PyQt5.QtGui import QRegExpValidator
from PyQt5.QtCore import pyqtSlot
import sqlite3 
import os
import re
import numpy as np 
import pandas as pd
class NumericDelegate(QStyledItemDelegate):
    def createEditor(self, parent, option, index):
        editor = super(NumericDelegate, self).createEditor(parent, option, index)
        if isinstance(editor, QLineEdit):
            reg_ex = QRegExp("[0-9]+.?[0-9]{,2}")
            validator = QRegExpValidator(reg_ex, editor)
            editor.setValidator(validator)
        return editor
class Ui_MainWindow(object):
   
    def submit(self):
     
        rowCount = self.tableWidgetInput.rowCount()
        columnCount = self.tableWidgetInput.columnCount()
        max_sum = 0
        global TMatrix,Ri,Ci,RiplusCi,RiMinusCi,inputArray_2D
        if (rowCount==columnCount):
            size=rowCount
            print("The size of the matrxi is %d * %d "%(size,size))
            print("The Given  matrxi is",  "SUM of Row" )
            rowData =[]
            
            for row in range(size):
                for column in range (size):
                        widegetItem = self.tableWidgetInput.item(row,column)
                        
                        if widegetItem and widegetItem.text():
                            rowData.append(float(widegetItem.text()) )
                        else:
                            rowData.append('NULL')
            print(rowData)
            inputArray = np.array(rowData,dtype=np.float64)  ###convert the list into numpy array.
            print(inputArray)
            size_rowdata = len(rowData)
            print("The total number of elemets are ",size_rowdata)
            inputArray_2D = np.reshape(inputArray, (rowCount, columnCount))   ### Reshape the numpy array into 2D
            print(inputArray_2D)
            sumofCol = np.sum(inputArray_2D,axis = 0,dtype='float')  ###find the sum of Column
            sumofRow = np.sum(inputArray_2D,axis = 1,dtype='float') ### find the sum of Row     
            maxInCol = np.amax(sumofCol)
            maxInRows = np.amax(sumofRow)
            print( "The Sum of Column is : ",sumofCol)
            print( "The Sum of Row is :",sumofRow)
            print( "The Maximum value in the  Column is :",maxInCol)
            print( "The Maximum value in the  Row is  : ",maxInRows)  
                   
        else:
            print("The input  is not a Square matrix")
            print("Data is not Submitted Sucessfully")

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1500, 1200)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.tableWidgetInput = QtWidgets.QTableWidget(self.centralwidget)
        self.tableWidgetInput.setGeometry(QtCore.QRect(30, 90, 1049, 520))
        self.tableWidgetInput.setObjectName("tableWidgetInput")
        self.tableWidgetInput.setColumnCount(2)
        self.tableWidgetInput.setRowCount(2)
        delegate = NumericDelegate(self.tableWidgetInput)
        self.tableWidgetInput.setItemDelegate(delegate)
        self.pushButton_submit = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_submit.setGeometry(QtCore.QRect(350, 625, 131, 51))
        self.pushButton_submit.setObjectName("pushButton_submit")                                        
        self.pushButton_submit.clicked.connect(self.submit)                                                    
        MainWindow.setCentralWidget(self.centralwidget) 
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
       
        self.pushButton_submit.setText(_translate("MainWindow", "Submit"))
      
        
       
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_())

谢谢

其实我不知道这一点,但在你的问题结束之前,作为一个猜测,或者做些什么,检查一下它是否不等于一个空的qTable。所以,制作一个空的,保持空的或当场制作一个。

我不理解你的问题,你能指出如果按下按钮并获得一个带有空文本的项目会发生什么吗?@eyllanesc我想确保在单击“提交”按钮时,用值填充整个矩阵单元格。这样我可以进一步计算值,得到最终的输出,我没有问你这个问题。假设在单元格0x0中,它是一个空项,用户按下按钮,在这种情况下会发生什么?是否应该向用户显示一条消息,表明他填写了该项目?没有运行任何东西?等等。应该向用户发送一条信息,表明他填写了该项目。也不要运行任何东西,你应该指出,在你的职位