近期解决了:python plt与Qt的集成 需要导入的控件 from matplotlib.backends.backend_qt5 import NavigationToolbar2QT from matplotlib.figure import Figure from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
以上为加入控件后的图形 注:不能在Scene当中添加,报错:QGraphicsProxyWidget::setWidget: cannot embed widget 0x60000374b170 which is not a toplevel widget, and is not a child of an embedded widget
其它查询功能:df=conn.execute(“select * from your_table_name”) 删除功能:conn.execute(“delete from your_table_name where columns_name=’your_select'” 注:删除功能,在操作以后,QT5的Model是不会刷新的,包括model.select()也不起作用,只能重新设定model.setTable(your_table)才能起作用
# 清空标准数据重新写入计算参数函数:
def clear_x_add(self):
self.zj_parameter.clear() # 清空列表
self.list_x = []
# 将model的数据拿出来至list_data
row_n = table_model.rowCount()
column_n = table_model.columnCount()
list_data = pd.DataFrame(index=range(row_n), columns=range(column_n))
for i in range(row_n):
for j in range(column_n):
list_data.loc[i, j] = table_model.record(i).value(j)
get_x_list = list_data[list_data.columns[4:6]] # 我只需要4,5列
print(get_x_list)
# 用正则表达式找出自己需要参数,当然先要import re
get_x_compile = re.compile("[a-z]\'|[a-z]|[A-Z]")
for n in get_x_list[4] + get_x_list[5]: # python福利:列表相加
add_item = re.findall(get_x_compile, n)
for m in add_item:
if m not in self.list_x: # python福利:有不同元素就放入
self.list_x.append(m)
self.zj_parameter.appendPlainText(m + '=') # 顺便将数据写入列表
if 'H' not in self.list_x:
self.zj_parameter.appendPlainText('H')
print(self.list_x)
对文本框写入的公式需要进行=号前后数据判断:
>>> a
'33'
>>> b
33.33
>>>
>>>
>>>
>>> def check_a(x):
... try:
... if x.isdigit() is True:
... print('True')
... else:
... print('False')
... except:
... print('Data Wrong',type(x))
...
>>>
>>>
>>>
>>> check_a(a)
True
>>> a.isdigit()
True
>>>
>>>
>>> check_a(b)
Data Wrong <class 'float'>
>>>
>>>
>>>
>>>
>>> check_a(c)
False
>>> c
'this is string'