1 Star 0 Fork 20

wain/Qtweiniu

forked from 1ndu5try/Qtweiniu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mainwindow.cpp 27.94 KB
一键复制 编辑 原始数据 按行查看 历史
unknown 提交于 2022-08-04 19:07 . tijao
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
#include "mainwindow.h"
#include "loginform.h"
#include "ui_mainwindow.h"
#include<QValueAxis>
#include<QtMath>
#include <QDesktopWidget>
#include<QDebug>
#include<QHeaderView>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
creactTips();//生成隐藏的标签
initAll();//对程序的基本初始化设置
initPlot();//初始化图表
}
class MainWindow::MyAxisTickerText : public QCPAxisTickerText
{
protected:
virtual QVector<double> createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE
{
Q_UNUSED(tickStep)
QVector<double> result;
if (mTicks.isEmpty())
return result;
auto start = mTicks.lowerBound(range.lower);
auto end = mTicks.upperBound(range.upper);
if (start != mTicks.constBegin()) --start;
if (end != mTicks.constEnd()) ++end;
int count = cleanMantissa(std::distance(start, end) / double(mTickCount + 1e-10));
auto it = start;
while (it != end) {
result.append(it.key());
int step = count;
if (step == 0) ++it;
while (--step >= 0 && it != end)
++it;
}
return result;
}
};
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initAll()
{
ui->stackedWidget->setCurrentIndex(0);
setWindowFlags(Qt::FramelessWindowHint);
mLocation = this->geometry();
mIsMax = false;
mDrag = false;
QAction *search_action = new QAction;
search_action->setToolTip("搜索");//设置鼠标悬浮的提示
search_action->setIcon(QIcon(":/png/查询.png"));
ui->lineEdit->addAction(search_action, QLineEdit::LeadingPosition);
//查询框的实现
ui->toolButton->setMouseTracking(true);
ui->toolButton_2->setMouseTracking(true);
ui->toolButton_3->setMouseTracking(true);
ui->toolButton_4->setMouseTracking(true);
ui->toolButton_5->setMouseTracking(true);
ui->toolButton->installEventFilter(this);
ui->toolButton_2->installEventFilter(this);
ui->toolButton_3->installEventFilter(this);
ui->toolButton_4->installEventFilter(this);
ui->toolButton_5->installEventFilter(this);
ui->toolButton_6->installEventFilter(this);
ui->toolButton_7->installEventFilter(this);
ui->toolButton_8->installEventFilter(this);
ui->toolButton_9->installEventFilter(this);
ui->toolButton_10->installEventFilter(this);
ui->widgetTitle->installEventFilter(this);
//为以上按钮添加过滤器,使得鼠标事件得以被监听
QTimer * timer = new QTimer(this);
timer->start(1000);
connect(timer,&QTimer::timeout,[=](){
QDateTime current_date_time = QDateTime::currentDateTime();
QString current_time = current_date_time.toString("yyyy.MM.dd hh:mm:ss");
ui->label_72->setText(current_time);
});//实现时间显示
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_3->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_4->setEditTriggers(QAbstractItemView::NoEditTriggers);
//表格设置无法编辑
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget_2->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget_3->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget_4->setSelectionBehavior(QAbstractItemView::SelectRows);
//设置表格选中一行
ui->tableWidget->horizontalHeader()->setVisible(true);
ui->tableWidget_2->horizontalHeader()->setVisible(true);
ui->tableWidget_3->horizontalHeader()->setVisible(true);
ui->tableWidget_4->horizontalHeader()->setVisible(true);
ui->comboBox_2->setView(new QListView());
ui->comboBox_4->setView(new QListView());
//使combobox的下拉栏样式表得以实现
}
void MainWindow::initPlot()
{
QCPDataContainer<QCPFinancialData> datas;
QVector<double> timeDatas, MA5Datas, MA10Datas, MA20Datas, MA30Datas;
MA5Datas = calculateMA(rawDatas, 5);
MA10Datas = calculateMA(rawDatas, 10);
MA20Datas = calculateMA(rawDatas, 20);
MA30Datas = calculateMA(rawDatas, 30);
for (int i = 0; i < rawTimes.size(); ++i) {
timeDatas.append(i);
QCPFinancialData data;
data.key = i;
data.open = rawDatas.at(i).at(0);
data.close = rawDatas.at(i).at(1);
data.low = rawDatas.at(i).at(2);
data.high = rawDatas.at(i).at(3);
datas.add(data);
}
QCPFinancial *financial = new QCPFinancial(ui->widget_9->xAxis, ui->widget_9->yAxis2);
financial->setName("日K");
financial->setBrushPositive(QColor(255, 43, 82));
financial->setPenPositive(QColor(255, 43, 82));
financial->setBrushNegative(QColor(1, 200, 95));
financial->setPenNegative(QColor(1, 200, 95));
financial->data()->set(datas);
const QVector<QColor> ColorOptions = {
"#c23531", "#2f4554", "#61a0a8", "#d48265"
};
QCPGraph *graph = ui->widget_9->addGraph(ui->widget_9->xAxis, ui->widget_9->yAxis2);
graph->setName("MA5");
graph->setData(timeDatas, MA5Datas);
graph->setPen(ColorOptions.at(0));
graph = ui->widget_9->addGraph(ui->widget_9->xAxis, ui->widget_9->yAxis2);
graph->setName("MA10");
graph->setData(timeDatas, MA10Datas);
graph->setPen(ColorOptions.at(1));
graph = ui->widget_9->addGraph(ui->widget_9->xAxis, ui->widget_9->yAxis2);
graph->setName("MA20");
graph->setData(timeDatas, MA20Datas);
graph->setPen(ColorOptions.at(2));
graph = ui->widget_9->addGraph(ui->widget_9->xAxis, ui->widget_9->yAxis2);
graph->setName("MA30");
graph->setData(timeDatas, MA30Datas);
graph->setPen(ColorOptions.at(3));
ui->widget_9->rescaleAxes();
ui->widget_9->xAxis->scaleRange(0.2, ui->widget_9->xAxis->range().center());
ui->widget_9->yAxis2->scaleRange(1.05, ui->widget_9->yAxis2->range().center());
ui->widget_9->yAxis->setVisible(false);
ui->widget_9->yAxis2->setVisible(true);
ui->widget_9->graph(2)->setBrush(QBrush(QColor(255,50,30,20)));
ui->widget_9->graph(2)->setChannelFillGraph( ui->widget_9->graph(3));
QCPBars *volumePos_1 = new QCPBars(ui->widget_9->xAxis, ui->widget_9->yAxis);
QCPBars *volumeNeg_1 = new QCPBars(ui->widget_9->xAxis, ui->widget_9->yAxis);
//主图表下方柱状图
for (int i=0; i<88; ++i)
{
int v = std::rand()%18+std::rand()%10;
(v < 20 ? volumeNeg_1 : volumePos_1)->addData(i, v); // add data to either volumeNeg or volumePos, depending on sign of v
}
volumePos_1->setWidth(0.8);
volumePos_1->setPen(Qt::NoPen);
volumePos_1->setBrush(QColor(152, 226, 182,100));
volumeNeg_1->setWidth(0.8);
volumeNeg_1->setPen(Qt::NoPen);
volumeNeg_1->setBrush(QColor(255, 138, 165,100));
QList<QCPAxis*> axes;
axes << ui->widget_9->yAxis2 << ui->widget_9->xAxis2 << ui->widget_9->xAxis;
ui->widget_9->axisRect()->setRangeDragAxes(axes);//设置axes中的轴可以被拖动
QFont font;//实例化QFont对象
font.setFamily("微软雅黑");//字体
ui->widget_9->yAxis2->setSubTicks(false);
ui->widget_9->yAxis2->setTickLabelFont(font);
ui->widget_9->yAxis2->setTickPen(QPen(QColor(170,170,170)));
ui->widget_9->yAxis2->setTickLabelColor(QColor(170,170,170));
ui->widget_9->yAxis2->setBasePen(QPen(QColor(255,255,255)));
ui->widget_9->yAxis2->grid()->setPen(QPen(QColor(220, 220, 220), 1, Qt::PenStyle::SolidLine));//网格白色虚线
ui->widget_9->yAxis2->grid()->setVisible(true);
ui->widget_9->xAxis->setBasePen(Qt::NoPen);
ui->widget_9->xAxis->setTickLabels(false);
ui->widget_9->xAxis->setTicks(false); // only want vertical grid in main axis rect, so hide xAxis backbone, ticks, and labels
//以上 正图
//以下 副图
QSharedPointer<QCPAxisTickerText> textTicker_1(new MyAxisTickerText); // 文字轴
textTicker_1->setTickCount(8);
QVector<double> x,y;
for (int i = 0; i < rawTimes.size(); ++i) {
textTicker_1->addTick(i, rawTimes.at(i));
}
QCPAxisRect *volumeAxisRect = new QCPAxisRect(ui->widget_9);
volumeAxisRect->axis(QCPAxis::atLeft)->setVisible(false);
volumeAxisRect->axis(QCPAxis::atRight)->setVisible(true);
volumeAxisRect->axis(QCPAxis::atBottom)->setTicker(textTicker_1);
volumeAxisRect->axis(QCPAxis::atRight)->setSubTicks(false);
ui->widget_9->plotLayout()->addElement(1, 0, volumeAxisRect);
volumeAxisRect->setMaximumSize(QSize(QWIDGETSIZE_MAX, 140));
//volumeAxisRect->axis(QCPAxis::atBottom)->setLayer("axes");
volumeAxisRect->axis(QCPAxis::atBottom)->grid()->setLayer("grid");
// bring bottom and main axis rect closer together:
ui->widget_9->plotLayout()->setRowSpacing(-5);
volumeAxisRect->setAutoMargins(QCP::msLeft|QCP::msRight|QCP::msBottom);
volumeAxisRect->setMargins(QMargins(0, 0, 0, 0));
// create two bar plottables, for positive (green) and negative (red) volume bars:
ui->widget_9->setAutoAddPlottableToLegend(false);
QCPBars *volumePos = new QCPBars(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atRight));
QCPBars *volumeNeg = new QCPBars(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atRight));
ui->widget_9->addGraph(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atRight));
for (int i=0; i<88; ++i)
{
int v = std::rand()%20000+std::rand()%20000+std::rand()%20000-25000;
(v < 0 ? volumeNeg : volumePos)->addData(i, v); // add data to either volumeNeg or volumePos, depending on sign of v
x.push_back(i);
y.push_back(5000 + qrand()%3000 );
}
volumePos->setWidth(0.8);
volumePos->setPen(Qt::NoPen);
volumePos->setBrush(QColor(1, 200, 95));
volumeNeg->setWidth(0.8);
volumeNeg->setPen(Qt::NoPen);
volumeNeg->setBrush(QColor(255, 43, 82));
ui->widget_9->graph(4)->setPen(QPen(QColor(21, 88, 231)));
ui->widget_9->graph(4)->addData(x,y);
// interconnect x axis ranges of main and bottom axis rects:
connect(ui->widget_9->xAxis, SIGNAL(rangeChanged(QCPRange)), volumeAxisRect->axis(QCPAxis::atBottom), SLOT(setRange(QCPRange)));
connect(volumeAxisRect->axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), ui->widget_9->xAxis, SLOT(setRange(QCPRange)));
// configure axes of both main and bottom axis rect:
volumeAxisRect->axis(QCPAxis::atBottom)->setSubTicks(false);
volumeAxisRect->axis(QCPAxis::atBottom)->setTickLabelFont(font);
volumeAxisRect->axis(QCPAxis::atBottom)->setTickPen(QPen(QColor(170,170,170)));
volumeAxisRect->axis(QCPAxis::atBottom)->setTickLabelColor(QColor(170,170,170));
volumeAxisRect->axis(QCPAxis::atBottom)->setBasePen(QPen(QColor(255,255,255)));
volumeAxisRect->axis(QCPAxis::atRight)->setSubTicks(false);
volumeAxisRect->axis(QCPAxis::atRight)->setTickLabelFont(font);
volumeAxisRect->axis(QCPAxis::atRight)->setTickPen(QPen(QColor(170,170,170)));
volumeAxisRect->axis(QCPAxis::atRight)->setTickLabelColor(QColor(170,170,170));
volumeAxisRect->axis(QCPAxis::atRight)->setBasePen(QPen(QColor(255,255,255)));
volumeAxisRect->axis(QCPAxis::atRight)->ticker()->setTickCount(3);
volumeAxisRect->axis(QCPAxis::atRight)->grid()->setPen(QPen(QColor(220, 220, 220), 1, Qt::PenStyle::SolidLine));//网格白色虚线
volumeAxisRect->axis(QCPAxis::atRight)->grid()->setVisible(true);
// make axis rects' left side line up:
QCPMarginGroup *group = new QCPMarginGroup(ui->widget_9);
ui->widget_9->axisRect()->setMarginGroup(QCP::msLeft|QCP::msRight, group);
ui->widget_9->xAxis->scaleRange(0.5, ui->widget_9->xAxis->range().center());
volumeAxisRect->setMarginGroup(QCP::msLeft|QCP::msRight, group);
ui->widget_9->rescaleAxes();
ui->widget_9->yAxis->setRange(0,150);
ui->widget_9->replot();
}
QVector<double> MainWindow::calculateMA(const QVector<QVector<double> > &v, int dayCount)
{
auto func = [](double result, const QVector<double> &v2){
return result + v2[1];
};
QVector<double> result;
for (int i = 0; i < v.size(); ++i) {
if (i < dayCount) {
result.append(qQNaN());
} else {
double sum = std::accumulate(v.begin() + i - dayCount + 1, v.begin() + i + 1, 0.0, func);
result.append(sum / dayCount);
}
}
return result;
}
void MainWindow::creactTips()
{
tip1 = new QLabel(this);
tip1->resize(75, 43);
tip1->setStyleSheet("border-image: url(:/png/自选.png);");
tip1->hide();
tip2 = new QLabel(this);
tip2->resize(75, 43);
tip2->setStyleSheet("border-image: url(:/png/个股.png);");
tip2->hide();
tip3 = new QLabel(this);
tip3->resize(75, 43);
tip3->setStyleSheet("border-image: url(:/png/市场.png);");
tip3->hide();
tip4 = new QLabel(this);
tip4->resize(80, 44);
tip4->setStyleSheet("border-image: url(:/png/选股器.png);");
tip4->hide();
tip5 = new QLabel(this);
tip5->resize(80, 44);
tip5->setStyleSheet("border-image: url(:/png/自定义.png);");
tip5->hide();
tip6 = new QLabel(this);
tip6->resize(85, 46);
tip6->setStyleSheet("border-image: url(:/png/意见反馈.png);");
tip6->hide();
tip7 = new QLabel(this);
tip7->resize(75, 43);
tip7->setStyleSheet("border-image: url(:/png/设置.png);");
tip7->hide();
tip8 = new QLabel(this);
tip8->resize(75, 50);
tip8->setStyleSheet("border-image: url(:/png/消息.png);");
tip8->hide();
tip9 = new QLabel(this);
tip9->resize(85, 50);
tip9->setStyleSheet("border-image: url(:/png/添加组件.png);");
tip9->hide();
tip10 = new QLabel(this);
tip10->resize(90, 50);
tip10->setStyleSheet("border-image: url(:/png/最小化组件.png);");
tip10->hide();
}
bool MainWindow::eventFilter(QObject *obj, QEvent *e)
{
if (obj == ui->widgetTitle)
{
if(e->type() == QEvent::MouseButtonDblClick)
{
on_btnMax_clicked();
return true;
}
}
if(obj ==ui->toolButton){
if(e->type() == QEvent::Enter){
//已经隐藏就显示出来
tip1->show();
QPoint point = ui->toolButton->pos();
point.rx() = point.x() + ui->toolButton->width() + 10;
point.ry() = point.y() - 5 ;
tip1->move(point);
tip1->raise();//显示最顶层
return true;
}
else if(e->type() == QEvent::Leave){
if(!tip1->isHidden()){
tip1->hide();
return true;
}
}
}
if(obj ==ui->toolButton_2){
if(e->type() == QEvent::Enter){
if (tip2->isHidden()) { //已经隐藏就显示出来
tip2->show();
QPoint point = ui->toolButton_2->pos();
point.rx() = point.x() + ui->toolButton_2->width() + 10;
point.ry() = point.y() - 5 ;
tip2->move(point);
tip2->raise();//显示最顶层
return true;
}}
else if(e->type() == QEvent::Leave){
if(!tip2->isHidden()){
tip2->hide();
return true;
}
}
}
if(obj ==ui->toolButton_3){
if(e->type() == QEvent::Enter){
if (tip3->isHidden()) { //已经隐藏就显示出来
tip3->show();
QPoint point = ui->toolButton_3->pos();
point.rx() = point.x() + ui->toolButton_3->width() + 10;
point.ry() = point.y() - 5 ;
tip3->move(point);
tip3->raise();//显示最顶层
return true;
}}
else if(e->type() == QEvent::Leave){
if(!tip3->isHidden()){
tip3->hide();
return true;
}
}
}
if(obj ==ui->toolButton_4){
if(e->type() == QEvent::Enter){
if (tip4->isHidden()) { //已经隐藏就显示出来
tip4->show();
QPoint point = ui->toolButton_4->pos();
point.rx() = point.x() + ui->toolButton_4->width() + 10;
point.ry() = point.y() - 5 ;
tip4->move(point);
tip4->raise();//显示最顶层
return true;
}}
else if(e->type() == QEvent::Leave){
if(!tip4->isHidden()){
tip4->hide();
return true;
}
}
}
if(obj ==ui->toolButton_5){
if(e->type() == QEvent::Enter){
if (tip5->isHidden()) { //已经隐藏就显示出来
tip5->show();
QPoint point = ui->toolButton_5->pos();
point.rx() = point.x() + ui->toolButton_5->width() + 10;
point.ry() = point.y() - 5 ;
tip5->move(point);
tip5->raise();//显示最顶层
return true;
}}
else if(e->type() == QEvent::Leave){
if(!tip5->isHidden()){
tip5->hide();
return true;
}
}
}
//
if(obj ==ui->toolButton_6){
if(e->type() == QEvent::Enter){
//已经隐藏就显示出来
tip6->show();
QPoint point = ui->toolButton_6->pos();
point.rx() = point.x() + ui->toolButton_6->width() + 10;
point.ry() = point.y() - 5 ;
tip6->move(point);
tip6->raise();//显示最顶层
return true;
}
else if(e->type() == QEvent::Leave){
if(!tip6->isHidden()){
tip6->hide();
return true;
}
}
}
if(obj ==ui->toolButton_7){
if(e->type() == QEvent::Enter){
//已经隐藏就显示出来
tip7->show();
QPoint point = ui->toolButton_7->pos();
point.rx() = point.x() + ui->toolButton_7->width() + 10;
point.ry() = point.y() - 5 ;
tip7->move(point);
tip7->raise();//显示最顶层
return true;
}
else if(e->type() == QEvent::Leave){
tip7->hide();
return true;
}
}
if(obj ==ui->toolButton_8){
if(e->type() == QEvent::Enter){
//已经隐藏就显示出来
tip8->show();
//ui->toolButton_8->pos()
QPoint point = ui->toolButton_8->pos();
point.rx() = point.x() + 1267;
point.ry() = point.y() + 30;
tip8->move(point);
tip8->raise();//显示最顶层
return true;
}
else if(e->type() == QEvent::Leave){
if(!tip8->isHidden()){
tip8->hide();
return true;
}
}
}
if(obj ==ui->toolButton_9){
if(e->type() == QEvent::Enter){
//已经隐藏就显示出来
tip9->show();
QPoint point = ui->toolButton_9->pos();
point.rx() = point.x() + 1265;
point.ry() = point.y() + 30;
tip9->move(point);
tip9->raise();//显示最顶层
return true;
}
else if(e->type() == QEvent::Leave){
if(!tip9->isHidden()){
tip9->hide();
return true;
}
}
}
if(obj ==ui->toolButton_10){
if(e->type() == QEvent::Enter){
//已经隐藏就显示出来
tip10->show();
QPoint point = ui->toolButton_10->pos();
point.rx() = point.x() + 1260;
point.ry() = point.y() + 30;
tip10->move(point);
tip10->raise();//显示最顶层
return true;
}
else if(e->type() == QEvent::Leave){
if(!tip10->isHidden()){
tip10->hide();
return true;
}
}
}
return QObject::eventFilter(obj, e);
}
void MainWindow::mousePressEvent(QMouseEvent *e)//鼠标按下事件
{
if (e->button() == Qt::LeftButton)
{
mDrag = true;
mDragPos = e->globalPos() - pos();
e->accept();
}
return QMainWindow::mousePressEvent(e);
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)//鼠标移动事件
{
if (mDrag && e->buttons() && Qt::LeftButton)
{
move(e->globalPos() - mDragPos);
e->accept();
}
return QMainWindow::mouseMoveEvent(e);
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e)//鼠标释放事件
{
mDrag = false;
return QMainWindow::mouseReleaseEvent(e);
}
void MainWindow::on_btnMin_clicked()
{
showMinimized();
}
void MainWindow::on_btnMax_clicked()
{
if (mIsMax)
{
setGeometry(mLocation);
}
else
{
mLocation = geometry();
setGeometry(qApp->desktop()->availableGeometry());
}
mIsMax = !mIsMax;
}
void MainWindow::on_btnExit_clicked()
{
this->close();
}
void MainWindow::on_toolButton_clicked()
{
ui->toolButton->setChecked(true);
ui->toolButton_2->setChecked(false);
ui->toolButton_3->setChecked(false);
ui->toolButton_4->setChecked(false);
ui->toolButton_5->setChecked(false);
ui->stackedWidget->setCurrentIndex(2);
}
void MainWindow::on_toolButton_2_clicked()
{
ui->toolButton_2->setChecked(true);
ui->toolButton->setChecked(false);
ui->toolButton_3->setChecked(false);
ui->toolButton_4->setChecked(false);
ui->toolButton_5->setChecked(false);
ui->stackedWidget->setCurrentIndex(0);
}
void MainWindow::on_toolButton_3_clicked()
{
ui->toolButton_3->setChecked(true);
ui->toolButton->setChecked(false);
ui->toolButton_2->setChecked(false);
ui->toolButton_4->setChecked(false);
ui->toolButton_5->setChecked(false);
ui->stackedWidget->setCurrentIndex(2);
}
void MainWindow::on_toolButton_4_clicked()
{
ui->toolButton_4->setChecked(true);
ui->toolButton->setChecked(false);
ui->toolButton_2->setChecked(false);
ui->toolButton_3->setChecked(false);
ui->toolButton_5->setChecked(false);
ui->stackedWidget->setCurrentIndex(1);
}
void MainWindow::on_toolButton_5_clicked()
{
ui->toolButton_5->setChecked(true);
ui->toolButton->setChecked(false);
ui->toolButton_2->setChecked(false);
ui->toolButton_3->setChecked(false);
ui->toolButton_4->setChecked(false);
ui->stackedWidget->setCurrentIndex(4);
}
void MainWindow::on_pushButton_3_clicked()
{
if(newForm)
{
if(newForm->isHidden())
{
QPoint point = mapToGlobal(ui->pushButton_3->pos());
newForm->setGeometry(point.x() + 70,point.y() + 70,201,326);
newForm->show();
}
else {
newForm->hide();
}
}
else {
newForm = new LeftTopForm(this);
newForm->setMouseTracking(true);
QPoint point = mapToGlobal(ui->pushButton_3->pos());
newForm->setGeometry(point.x() + 70,point.y() + 70,201,326); //这里要调整好
newForm->show();
}
}
void MainWindow::on_pushButton_5_clicked()
{
ui->pushButton_5->setChecked(true);
ui->pushButton_6->setChecked(false);
ui->pushButton_7->setChecked(false);
ui->pushButton_8->setChecked(false);
ui->pushButton_9->setChecked(false);
pushBtnSelect = 1;
}
void MainWindow::on_pushButton_6_clicked()
{
ui->pushButton_5->setChecked(false);
ui->pushButton_6->setChecked(true);
ui->pushButton_7->setChecked(false);
ui->pushButton_8->setChecked(false);
ui->pushButton_9->setChecked(false);
pushBtnSelect = 2;
}
void MainWindow::on_pushButton_7_clicked()
{
ui->pushButton_5->setChecked(false);
ui->pushButton_6->setChecked(false);
ui->pushButton_7->setChecked(true);
ui->pushButton_8->setChecked(false);
ui->pushButton_9->setChecked(false);
pushBtnSelect = 3;
}
void MainWindow::on_pushButton_8_clicked()
{
ui->pushButton_5->setChecked(false);
ui->pushButton_6->setChecked(false);
ui->pushButton_7->setChecked(false);
ui->pushButton_8->setChecked(true);
ui->pushButton_9->setChecked(false);
pushBtnSelect = 4;
}
void MainWindow::on_pushButton_9_clicked()
{
ui->pushButton_5->setChecked(false);
ui->pushButton_6->setChecked(false);
ui->pushButton_7->setChecked(false);
ui->pushButton_8->setChecked(false);
ui->pushButton_9->setChecked(true);
pushBtnSelect = 5;
}
void MainWindow::on_toolButton_11_clicked()
{
loginForm = new LoginForm();
loginForm->move(QApplication::desktop()->screen()->rect().center() - loginForm->rect().center());
loginForm->show();
loginForm->raise();
}
void MainWindow::on_toolButton_6_clicked()
{
loginForm = new LoginForm();
loginForm->move(QApplication::desktop()->screen()->rect().center() - loginForm->rect().center());
loginForm->show();
loginForm->raise();
}
void MainWindow::on_toolButton_8_clicked()
{
loginForm = new LoginForm();
loginForm->move(QApplication::desktop()->screen()->rect().center() - loginForm->rect().center());
loginForm->show();
loginForm->raise();
}
void MainWindow::on_toolButton_12_clicked()
{
ui->toolButton_12->setChecked(true);
if(isChecked_1){
ui->toolButton_13->setChecked(false);
QPropertyAnimation * animation = new QPropertyAnimation(ui->line_3,"geometry");
animation->setDuration(500);
animation->setStartValue(QRect(ui->line_3->x(),ui->line_3->y(),ui->line_3->width(),ui->line_3->height()));
animation->setEndValue(QRect(25,30,ui->line_3->width(),ui->line_3->height()));
animation->setEasingCurve(QEasingCurve::OutQuint);
animation->start();
isChecked_1 = false;
}
}
void MainWindow::on_toolButton_13_clicked()
{
ui->toolButton_13->setChecked(true);
if(!isChecked_1){
ui->toolButton_12->setChecked(false);
QPropertyAnimation * animation = new QPropertyAnimation(ui->line_3,"geometry");
animation->setDuration(500);
animation->setStartValue(QRect(ui->line_3->x(),ui->line_3->y(),ui->line_3->width(),ui->line_3->height()));
animation->setEndValue(QRect(108,30,ui->line_3->width(),ui->line_3->height()));
animation->setEasingCurve(QEasingCurve::OutQuint);
animation->start();
isChecked_1 = true;
}
}
void MainWindow::on_toolButton_14_clicked()
{
ui->toolButton_14->setChecked(true);
if(isChecked_2){
ui->toolButton_15->setChecked(false);
QPropertyAnimation * animation = new QPropertyAnimation(ui->line_4,"geometry");
animation->setDuration(500);
animation->setStartValue(QRect(ui->line_4->x(),ui->line_4->y(),ui->line_4->width(),ui->line_4->height()));
animation->setEndValue(QRect(25,22,ui->line_4->width(),ui->line_4->height()));
animation->setEasingCurve(QEasingCurve::OutQuint);
animation->start();
isChecked_2 = false;
}
}
void MainWindow::on_toolButton_15_clicked()
{
ui->toolButton_15->setChecked(true);
if(!isChecked_2){
ui->toolButton_14->setChecked(false);
QPropertyAnimation * animation = new QPropertyAnimation(ui->line_4,"geometry");
animation->setDuration(500);
animation->setStartValue(QRect(ui->line_4->x(),ui->line_4->y(),ui->line_4->width(),ui->line_4->height()));
animation->setEndValue(QRect(115,22,ui->line_4->width(),ui->line_4->height()));
animation->setEasingCurve(QEasingCurve::OutQuint);
animation->start();
isChecked_2 = true;
}
}
void MainWindow::on_toolButton_16_clicked()
{
if(chooseForm)
{
if(chooseForm->isHidden())
{
QPoint point = mapToGlobal(ui->toolButton_16->pos());
chooseForm->setGeometry(point.x() + 130,point.y() + 130,409,500);
chooseForm->show();
}
else {
chooseForm->hide();
}
}
else {
chooseForm = new choosefram(this);
chooseForm->setMouseTracking(true);
QPoint point = mapToGlobal(ui->toolButton_16->pos());
chooseForm->setGeometry(point.x() + 130,point.y() + 130,409,500); //这里要调整好
chooseForm->show();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/volcanowain/qtweiniu.git
git@gitee.com:volcanowain/qtweiniu.git
volcanowain
qtweiniu
Qtweiniu
master

搜索帮助