增加flask作为后台,查看products.db数据库表的功能

This commit is contained in:
2025-11-29 08:04:13 +08:00
parent b32549c5df
commit 1c91dd45ed
13 changed files with 998 additions and 2778 deletions

View File

@@ -14,7 +14,8 @@ from PySide6.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayo
QWidget, QPushButton, QTableWidget, QTableWidgetItem,
QListWidget, QListWidgetItem, QSplitter, QFileDialog,
QLabel, QStatusBar, QMessageBox, QHeaderView, QComboBox,
QLineEdit, QGroupBox, QTextEdit, QStyledItemDelegate, QMenu)
QLineEdit, QGroupBox, QTextEdit, QStyledItemDelegate, QMenu,
QInputDialog)
from PySide6.QtCore import Qt, QSize
from PySide6.QtGui import QAction, QFontMetrics
@@ -244,6 +245,10 @@ class SQLiteViewer(QMainWindow):
# 设置行头自动调整高度
self.data_table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
# 启用行高调整功能 - 允许用户手动拖拽调整行高
self.data_table.verticalHeader().setSectionsMovable(False) # 行不允许移动
self.data_table.verticalHeader().setSectionResizeMode(QHeaderView.Interactive) # 允许手动调整行高
# 添加右键菜单支持
self.data_table.setContextMenuPolicy(Qt.CustomContextMenu)
self.data_table.customContextMenuRequested.connect(self.show_table_context_menu)
@@ -572,6 +577,14 @@ class SQLiteViewer(QMainWindow):
# 添加菜单项
auto_resize_action = menu.addAction("自动调整列宽")
auto_resize_rows_action = menu.addAction("自动调整行高")
# 添加行高调整子菜单
row_height_menu = menu.addMenu("设置行高")
increase_height_action = row_height_menu.addAction("增加行高 (+10px)")
decrease_height_action = row_height_menu.addAction("减少行高 (-10px)")
reset_height_action = row_height_menu.addAction("重置行高为默认值")
custom_height_action = row_height_menu.addAction("自定义行高...")
copy_action = menu.addAction("复制选中内容")
# 显示菜单
@@ -581,6 +594,14 @@ class SQLiteViewer(QMainWindow):
self.auto_resize_columns()
elif action == auto_resize_rows_action:
self.auto_resize_rows()
elif action == increase_height_action:
self.adjust_row_height(10)
elif action == decrease_height_action:
self.adjust_row_height(-10)
elif action == reset_height_action:
self.reset_row_height()
elif action == custom_height_action:
self.set_custom_row_height()
elif action == copy_action:
self.copy_selected_content()
@@ -613,6 +634,68 @@ class SQLiteViewer(QMainWindow):
self.status_bar.showMessage("已自动调整行高")
def adjust_row_height(self, delta: int):
"""调整选中行的行高"""
selected_items = self.data_table.selectedItems()
if not selected_items:
# 如果没有选中行,调整所有行
for row in range(self.data_table.rowCount()):
current_height = self.data_table.rowHeight(row)
new_height = max(current_height + delta, 20) # 最小行高20像素
self.data_table.setRowHeight(row, new_height)
self.status_bar.showMessage(f"所有行高已调整 {delta:+d} 像素")
else:
# 调整选中行
selected_rows = set(item.row() for item in selected_items)
for row in selected_rows:
current_height = self.data_table.rowHeight(row)
new_height = max(current_height + delta, 20) # 最小行高20像素
self.data_table.setRowHeight(row, new_height)
self.status_bar.showMessage(f"已调整 {len(selected_rows)} 行的行高 {delta:+d} 像素")
def reset_row_height(self):
"""重置行高为默认值"""
logger.info("重置行高为默认值")
# 重置为默认行高30像素
default_height = 30
for row in range(self.data_table.rowCount()):
self.data_table.setRowHeight(row, default_height)
self.status_bar.showMessage("行高已重置为默认值")
def set_custom_row_height(self):
"""设置自定义行高"""
# 获取当前选中行的行高作为默认值
selected_items = self.data_table.selectedItems()
if selected_items:
current_height = self.data_table.rowHeight(selected_items[0].row())
else:
current_height = 30
# 显示输入对话框
height, ok = QInputDialog.getInt(
self,
"设置行高",
"请输入行高(像素):",
current_height, # 默认值
20, # 最小值
500 # 最大值
)
if ok:
if selected_items:
# 设置选中行
selected_rows = set(item.row() for item in selected_items)
for row in selected_rows:
self.data_table.setRowHeight(row, height)
self.status_bar.showMessage(f"已设置 {len(selected_rows)} 行的行高为 {height} 像素")
else:
# 设置所有行
for row in range(self.data_table.rowCount()):
self.data_table.setRowHeight(row, height)
self.status_bar.showMessage(f"所有行高已设置为 {height} 像素")
def copy_selected_content(self):
"""复制选中的内容"""
selected_items = self.data_table.selectedItems()