#include "mainwindow.h" #include "ui_mainwindow.h" #include "view/coaldistributchartwidget.h" #include #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setWindowFlag(Qt::FramelessWindowHint); this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint); calendarLoopPlay(); addcoalDistributChart(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_close_clicked() { this->close(); } void MainWindow::on_pushButton_max_clicked() { if (isFullScreen()) { this->showMaximized(); } else { this->showFullScreen(); } } void MainWindow::on_pushButton_min_clicked() { this->showMinimized(); } void MainWindow::calendarLoopPlay() { ui->label_calendar->clear(); QTimer *timer_calendar = new QTimer(this); connect(timer_calendar, &QTimer::timeout, this, [this]() { QDateTime time = QDateTime::currentDateTime(); QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd"); ui->label_calendar->setText(str); }); timer_calendar->start(1000); //每一秒溢出一次进入槽函数 } void MainWindow::addcoalDistributChart() { CoalDistributChartWidget *coalDistributChartWidget = new CoalDistributChartWidget(ui->widget_coalDistributChart); // 可选:设置大小 coalDistributChartWidget->setMinimumSize(400, 300); // 设置最小大小以确保可见 // 确保将部件添加到布局中 QVBoxLayout *layout = qobject_cast(ui->widget_coalDistributChart->layout()); if (layout) { layout->addWidget(coalDistributChartWidget); } else { // 如果没有布局,可以手动添加部件 ui->widget_coalDistributChart->setLayout(new QVBoxLayout()); ui->widget_coalDistributChart->layout()->addWidget( coalDistributChartWidget); } }