2025-09-29 18:31:44 +08:00
|
|
|
|
#include "MyQUI.h"
|
2025-09-25 19:20:25 +08:00
|
|
|
|
|
|
|
|
|
|
static const std::string QSS_GROUP =
|
|
|
|
|
|
"QGroupBox { border: 1px solid gray; margin-top: 8px; border-radius: 5px;}"
|
|
|
|
|
|
"QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; left:10px; margin-left: 0px; padding:0 1px; }";
|
|
|
|
|
|
|
2025-09-29 18:31:44 +08:00
|
|
|
|
static const std::string QSS_BTN =
|
2025-10-26 20:43:51 +08:00
|
|
|
|
"QPushButton {background:rgba(180,180,180,50);border-radius:2px;border:1px solid gray;color:white;}"
|
|
|
|
|
|
"QPushButton:hover {background-color:rgb(32,164,128);}"
|
|
|
|
|
|
"QPushButton:pressed {border-width:2px 0 0 2px;border-style:inset;}";
|
2025-09-29 18:31:44 +08:00
|
|
|
|
|
|
|
|
|
|
static const std::string QSS_BTN_ACTIVE =
|
|
|
|
|
|
"QPushButton {background:rgba(80, 80, 80,80);border-radius:5px;border:1px solid green;color:green;font:bold 15px;}";
|
2025-09-25 19:20:25 +08:00
|
|
|
|
|
|
|
|
|
|
static const std::string QSS_BTN_MENU =
|
2025-09-29 18:31:44 +08:00
|
|
|
|
"QPushButton {background:rgba(19, 35, 71,200);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 18px;}"
|
|
|
|
|
|
"QPushButton:hover {background-color:rgb(32,164,128);}"
|
|
|
|
|
|
"QPushButton:pressed {border-width:3px 0 0 3px;border-style:inset;}"
|
|
|
|
|
|
"QPushButton:disabled {color:rgb(150,150,150);}";
|
|
|
|
|
|
|
|
|
|
|
|
static const std::string QSS_BTN_MENU_ACTIVE =
|
|
|
|
|
|
"QPushButton {background:rgba(32,164,128, 200);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 18px;}"
|
2025-09-25 19:20:25 +08:00
|
|
|
|
"QPushButton:hover {background-color:rgb(32,164,128);}"
|
2025-09-29 18:31:44 +08:00
|
|
|
|
"QPushButton:pressed {border-width:3px 0 0 3px;border-style:inset;}"
|
2025-09-25 19:20:25 +08:00
|
|
|
|
"QPushButton:disabled {color:rgb(150,150,150);}";
|
|
|
|
|
|
|
2025-10-09 18:37:18 +08:00
|
|
|
|
static const std::string QSS_BTN_TAB =
|
|
|
|
|
|
"QPushButton {background:rgba(80,80,80,100);color:white;border-radius:3px;border:1px solid rgb(10,120,215);}"
|
|
|
|
|
|
"QPushButton:hover {background-color:rgba(80,80,80,200);}";
|
|
|
|
|
|
//"QPushButton:pressed {border-width:3px 0 0 3px;border-style:inset;}"
|
|
|
|
|
|
//"QPushButton:disabled {color:rgb(150,150,150);}";
|
|
|
|
|
|
|
2025-09-25 19:20:25 +08:00
|
|
|
|
static const std::string QSS_LINE =
|
2025-10-26 20:43:51 +08:00
|
|
|
|
"QLineEdit { background-color:rgba(180,180,180,36); color:#ffffff; border:1px solid gray; border-radius:3px; font:bold 13px; }"; //14, 49, 66
|
2025-09-25 19:20:25 +08:00
|
|
|
|
|
2025-09-29 18:31:44 +08:00
|
|
|
|
static const std::string QSS_TABLE = // 表格整体样式
|
|
|
|
|
|
"QTableWidget {"
|
|
|
|
|
|
" background-color: transparent;" // 背景色
|
|
|
|
|
|
" gridline-color: #C0C0C0;" // 网格线颜色
|
|
|
|
|
|
" border: 1px solid gray;" // 边框
|
|
|
|
|
|
" color: white;" // 文字颜色
|
|
|
|
|
|
"}"
|
|
|
|
|
|
// 表头样式
|
|
|
|
|
|
"QHeaderView { background-color: rgba(150,150,150,50); }"
|
|
|
|
|
|
"QHeaderView::section {"
|
|
|
|
|
|
" background-color: rgba(120,120,120,0);" // 表头背景
|
|
|
|
|
|
" padding: 4px;" // 内边距
|
|
|
|
|
|
" border: 1px solid #505050;" // 边框
|
|
|
|
|
|
" min-height: 25px;" // 最小高度
|
|
|
|
|
|
"}"
|
|
|
|
|
|
// 单元格样式
|
|
|
|
|
|
"QTableWidget::item {"
|
|
|
|
|
|
" padding-left: 5px;"
|
|
|
|
|
|
" border-bottom: 1px solid gray;" // 底部边框
|
|
|
|
|
|
"}"
|
|
|
|
|
|
// 选中状态
|
|
|
|
|
|
"QTableWidget::item:selected {"
|
|
|
|
|
|
" background-color: rgba(184, 214, 255, 50);" // 选中背景色
|
|
|
|
|
|
" color: rgb(220,220,220);" // 选中文字颜色
|
|
|
|
|
|
"}";
|
|
|
|
|
|
|
2025-10-09 18:37:18 +08:00
|
|
|
|
static const std::string QSS_BTN_COMBOX =
|
|
|
|
|
|
"QComboBox { background-color: transparent; border: 1px solid rgb(18, 251, 255)}"
|
|
|
|
|
|
"QListView::item { background-color: rgba(80,80,80,200); color: white; padding-left: 10px; }";
|
|
|
|
|
|
|
2025-09-29 18:31:44 +08:00
|
|
|
|
MyWidget::MyWidget(QWidget* parent) : QWidget(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 可以在这里设置样式表,也可以在其他地方设置
|
|
|
|
|
|
setObjectName("MyWidget");
|
|
|
|
|
|
setStyleSheet("#MyWidget {background-color:rgba(120,120,120,80); border-radius:5px;}");
|
|
|
|
|
|
// 确保自动填充背景
|
|
|
|
|
|
setAutoFillBackground(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-26 20:43:51 +08:00
|
|
|
|
shared_ptr<QPushButton> MyQUI::Button(QWidget* parent, int x, int y, int w, int h, std::string title)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto btn = std::make_shared<QPushButton>(title.c_str(), parent);
|
|
|
|
|
|
btn->setGeometry(x, y, w, h);
|
|
|
|
|
|
btn->setStyleSheet(QSS_BTN.c_str());
|
|
|
|
|
|
return btn;
|
|
|
|
|
|
}
|
2025-09-29 18:31:44 +08:00
|
|
|
|
|
2025-09-25 19:20:25 +08:00
|
|
|
|
std::shared_ptr<QGroupBox> MyQUI::GroupBox(QWidget* parent, int x, int y, int w, int h, std::string title)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto groupBox = std::make_shared<QGroupBox>(title.c_str(), parent);
|
|
|
|
|
|
groupBox->setGeometry(x, y, w, h);
|
|
|
|
|
|
groupBox->setStyleSheet(QSS_GROUP.c_str());
|
|
|
|
|
|
return groupBox;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-29 18:31:44 +08:00
|
|
|
|
MyPairLabelLine MyQUI::PairLine(QWidget* parent, int x, int y, string k, string v, bool readonly/* = true*/)
|
2025-09-25 19:20:25 +08:00
|
|
|
|
{
|
2025-09-29 18:31:44 +08:00
|
|
|
|
shared_ptr<QLabel> key = make_shared<QLabel>(parent);
|
2025-09-25 19:20:25 +08:00
|
|
|
|
key->setText(k.c_str());
|
|
|
|
|
|
key->setGeometry(x, y, 80, 26);
|
2025-09-29 18:31:44 +08:00
|
|
|
|
shared_ptr<QLineEdit> value = make_shared<QLineEdit>(parent);
|
2025-09-25 19:20:25 +08:00
|
|
|
|
value->setText(v.c_str());
|
|
|
|
|
|
value->setGeometry(x+80, y, 260, 26);
|
|
|
|
|
|
value->setStyleSheet(QSS_LINE.c_str());
|
2025-09-29 18:31:44 +08:00
|
|
|
|
value->setReadOnly(readonly);
|
|
|
|
|
|
return {key, value};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-09 18:37:18 +08:00
|
|
|
|
std::shared_ptr<QTableWidget> MyQUI::TableWidget(QWidget* parent, int x, int y, int w, int h)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto table = std::make_shared<QTableWidget>(parent);
|
|
|
|
|
|
table->setGeometry(x, y, w, h);
|
|
|
|
|
|
table->setStyleSheet(QSS_TABLE.c_str());
|
|
|
|
|
|
table->horizontalHeader()->setStretchLastSection(true); // 最后一列占满
|
|
|
|
|
|
table->verticalHeader()->setVisible(false); // 不显示垂直表头
|
|
|
|
|
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers); // 单元格不可编辑
|
|
|
|
|
|
table->setSelectionMode(QAbstractItemView::SingleSelection); // 设置为单选模式
|
|
|
|
|
|
table->setSelectionBehavior(QAbstractItemView::SelectRows); // 设置为整行选中
|
|
|
|
|
|
table->horizontalHeader()->setFixedHeight(50);
|
|
|
|
|
|
table->horizontalHeader()->setDefaultSectionSize(60);
|
|
|
|
|
|
return table;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-29 18:31:44 +08:00
|
|
|
|
void MyQUI::setTableCell(std::shared_ptr<QTableWidget> table, int row, int col, std::string text, std::string style /*= ""*/)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (row >= table->rowCount())
|
|
|
|
|
|
{
|
|
|
|
|
|
table->insertRow(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
auto item = table->item(row, col);
|
|
|
|
|
|
if (!item)
|
|
|
|
|
|
{
|
|
|
|
|
|
item = new QTableWidgetItem();
|
|
|
|
|
|
table->setItem(row, col, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
item->setText(text.c_str());
|
|
|
|
|
|
if (style == "OK") { item->setForeground(QBrush(Qt::green)); }
|
|
|
|
|
|
else if (style == "ERR") { item->setForeground(QBrush(Qt::red)); }
|
|
|
|
|
|
else if (style == "WARN") { item->setForeground(QBrush(Qt::cyan)); }
|
2025-09-25 19:20:25 +08:00
|
|
|
|
}
|