qt_demoe/flatui/frmflatui.cpp

100 lines
4.3 KiB
C++
Raw Normal View History

2019-09-29 00:49:38 +00:00
#pragma execution_character_set("utf-8")
#include "frmflatui.h"
#include "ui_frmflatui.h"
#include "flatui.h"
#include "qdebug.h"
#include "qdesktopwidget.h"
#include "qdatetime.h"
frmFlatUI::frmFlatUI(QWidget *parent) : QWidget(parent), ui(new Ui::frmFlatUI)
{
ui->setupUi(this);
this->initForm();
}
frmFlatUI::~frmFlatUI()
{
delete ui;
}
void frmFlatUI::initForm()
{
ui->bar1->setRange(0, 100);
ui->bar2->setRange(0, 100);
ui->slider1->setRange(0, 100);
ui->slider2->setRange(0, 100);
connect(ui->slider1, SIGNAL(valueChanged(int)), ui->bar1, SLOT(setValue(int)));
connect(ui->slider2, SIGNAL(valueChanged(int)), ui->bar2, SLOT(setValue(int)));
ui->slider1->setValue(30);
ui->slider2->setValue(30);
this->setStyleSheet("*{outline:0px;}QWidget#frmFlatUI{background:#FFFFFF;}");
FlatUI::Instance()->setPushButtonQss(ui->btn1);
FlatUI::Instance()->setPushButtonQss(ui->btn2, 5, 8, "#1ABC9C", "#E6F8F5", "#2EE1C1", "#FFFFFF", "#16A086", "#A7EEE6");
FlatUI::Instance()->setPushButtonQss(ui->btn3, 5, 8, "#3498DB", "#FFFFFF", "#5DACE4", "#E5FEFF", "#2483C7", "#A0DAFB");
FlatUI::Instance()->setPushButtonQss(ui->btn4, 5, 8, "#E74C3C", "#FFFFFF", "#EC7064", "#FFF5E7", "#DC2D1A", "#F5A996");
FlatUI::Instance()->setLineEditQss(ui->txt1);
FlatUI::Instance()->setLineEditQss(ui->txt2, 5, 2, "#DCE4EC", "#1ABC9C");
FlatUI::Instance()->setLineEditQss(ui->txt3, 3, 1, "#DCE4EC", "#3498DB");
FlatUI::Instance()->setLineEditQss(ui->txt4, 3, 1, "#DCE4EC", "#E74C3C");
FlatUI::Instance()->setProgressQss(ui->bar1);
FlatUI::Instance()->setProgressQss(ui->bar2, 8, 5, 9, "#E8EDF2", "#1ABC9C");
FlatUI::Instance()->setSliderQss(ui->slider1);
FlatUI::Instance()->setSliderQss(ui->slider2, 10, "#E8EDF2", "#E74C3C", "#E74C3C");
FlatUI::Instance()->setSliderQss(ui->slider3, 10, "#E8EDF2", "#34495E", "#34495E");
FlatUI::Instance()->setRadioButtonQss(ui->rbtn1);
FlatUI::Instance()->setRadioButtonQss(ui->rbtn2, 8, "#D7DBDE", "#1ABC9C");
FlatUI::Instance()->setRadioButtonQss(ui->rbtn3, 8, "#D7DBDE", "#3498DB");
FlatUI::Instance()->setRadioButtonQss(ui->rbtn4, 8, "#D7DBDE", "#E74C3C");
FlatUI::Instance()->setScrollBarQss(ui->horizontalScrollBar);
FlatUI::Instance()->setScrollBarQss(ui->verticalScrollBar, 8, 120, 20, "#606060", "#34495E", "#1ABC9C", "#E74C3C");
//设置列数和列宽
int width = qApp->desktop()->availableGeometry().width() - 120;
ui->tableWidget->setColumnCount(5);
ui->tableWidget->setColumnWidth(0, width * 0.06);
ui->tableWidget->setColumnWidth(1, width * 0.10);
ui->tableWidget->setColumnWidth(2, width * 0.06);
ui->tableWidget->setColumnWidth(3, width * 0.10);
ui->tableWidget->setColumnWidth(4, width * 0.20);
ui->tableWidget->verticalHeader()->setDefaultSectionSize(25);
QStringList headText;
headText << "设备编号" << "设备名称" << "设备地址" << "告警内容" << "告警时间";
ui->tableWidget->setHorizontalHeaderLabels(headText);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget->setAlternatingRowColors(true);
ui->tableWidget->verticalHeader()->setVisible(false);
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
//设置行高
ui->tableWidget->setRowCount(300);
for (int i = 0; i < 300; i++) {
ui->tableWidget->setRowHeight(i, 24);
QTableWidgetItem *itemDeviceID = new QTableWidgetItem(QString::number(i + 1));
QTableWidgetItem *itemDeviceName = new QTableWidgetItem(QString("测试设备%1").arg(i + 1));
QTableWidgetItem *itemDeviceAddr = new QTableWidgetItem(QString::number(i + 1));
QTableWidgetItem *itemContent = new QTableWidgetItem("防区告警");
QTableWidgetItem *itemTime = new QTableWidgetItem(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
ui->tableWidget->setItem(i, 0, itemDeviceID);
ui->tableWidget->setItem(i, 1, itemDeviceName);
ui->tableWidget->setItem(i, 2, itemDeviceAddr);
ui->tableWidget->setItem(i, 3, itemContent);
ui->tableWidget->setItem(i, 4, itemTime);
}
}