(obj);if (pWidget){m_pTitleLabel->setText(pWidget->windowTitle());return true;}}default:return QWidget::eventFilter(obj, event);}return QWidget::eventFilter(obj, event);}//void TitleBar::onClicked()//{//QPushButton *pButton = qobject_cast(sender());//QWidget *pWindow = this->window();//if (pWindow->isTopLevel())//{//}//}
.cpp
#include "widget.h"#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include#include "title_bar.h"#include #include Widget::Widget(QWidget *parent): QWidget(parent){/********************配色*****************/QMainWindow *pw = new QMainWindow;//QPalette palette = this->palette();//palette.setColor(QPalette::Window, QColor(4, 7, 38));//改变控件背景色//this->setPalette(palette);/*********************************布局*********************************///QGridLayout *baseLayout = new QGridLayout();//布局管理器/**********************设置可停靠窗口******************/QDockWidget *pd1 = new QDockWidget;QDockWidget *pd2 = new QDockWidget;QDockWidget *pd3 = new QDockWidget;pw->addDockWidget(Qt::RightDockWidgetArea,pd1);pw->addDockWidget(Qt::BottomDockWidgetArea,pd2);pw->addDockWidget(Qt::LeftDockWidgetArea,pd3);pd1->setAllowedAreas(Qt::RightDockWidgetArea|Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea );//设置顶部不可停靠pd2->setAllowedAreas( Qt::BottomDockWidgetArea|Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea );pd3->setAllowedAreas( Qt::BottomDockWidgetArea|Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea );pw->setDockOptions(QMainWindow::AnimatedDocks);//设置停靠参数,不允许重叠,只允许拖动/********************Creating Donutchart*****************///可停靠窗口1QChartView *chartView;chartView=new QChartView(creatDonutChart());chartView->setRenderHint(QPainter::Antialiasing);//渲染抗锯齿//以下代码可以实现在一个DockWidget中显示多个chart,直接在nn后面addwidget即可QWidget *mm = new QWidget();QGridLayout *nn = new QGridLayout();nn->addWidget(chartView);mm->setLayout(nn);pd1->setWidget(mm);pd1=m_titlebar(pd1,chartView,"Donutchart Chart");//*******************Creating Bar Chart*********************////可停靠窗口2chartView=new QChartView(creatBarChart());chartView->setRenderHint(QPainter::Antialiasing);//渲染抗锯齿//以下代码可以实现在一个DockWidget中显示多个chart,直接在nn后面addwidget即可mm = new QWidget();nn = new QGridLayout();nn->addWidget(chartView);mm->setLayout(nn);pd2->setWidget(mm);pd2=m_titlebar(pd2,chartView,"Bar Chart");/********************Creating Line Chart************************//*************************AreaChart Example*************************///可停靠窗口3chartView = new QChartView(creatAreaChart());chartView->setRenderHint(QPainter::Antialiasing);//以下代码可以实现在一个DockWidget中显示多个chart,直接在nn后面addwidget即可mm = new QWidget();nn = new QGridLayout();nn->addWidget(chartView);mm->setLayout(nn);pd3->setWidget(mm);pd3=m_titlebar(pd3,chartView,"AreaChart");/**************************主窗口****************************/chartView=new QChartView(creatLineChart());chartView->setRenderHint(QPainter::Antialiasing);pw->setCentralWidget(chartView);/*************************大屏显示**************************/pw->setWindowFlags (Qt::FramelessWindowHint);//去掉标题栏,但不能鼠标缩放窗口pw->showFullScreen();}Widget::~Widget(){}QChart *Widget::creatDonutChart() const{QPieSeries *series=new QPieSeries();series->setHoleSize(0.35);//圆孔大小series->append("Protein 4.2%",4.2);QPieSlice *slice=series->append("Fat 15.6%",15.6);//单个切片slice->setExploded();//使该切片突出slice->setLabelVisible();//显示切片的标签series->append("Other 23.8%", 23.8);series->append("Carbs 56.4%", 56.4);//若以圆心为原点,作xoy坐标系,则以y轴为起始轴,圆环的每一小部分按照编程顺序顺时针排列 。QChart *chart = new QChart;chart->setTitle("Donut with a lemon glaze (100g)");chart->addSeries(series);chart->legend()->setAlignment(Qt::AlignBottom);//图例放在底部chart->setTheme(QChart::ChartThemeBlueCerulean);//主题颜色设置为天然色chart->legend()->setFont(QFont("Arial",7));//图例字体宋体7号字//标题栏return chart;}QChart *Widget::creatBarChart() const{//本示例要展示五个人在每个月的某项数据,比如每个月掉多少头发//创建要展示的对象,本示例中是姓名,并设置不同对象在每个月的数据QBarSet *set0 = new QBarSet("Jane");QBarSet *set1 = new QBarSet("John");QBarSet *set2 = new QBarSet("Axel");QBarSet *set3 = new QBarSet("Mary");QBarSet *set4 = new QBarSet("Sama");*set0