岳阳有哪几家做网站的廉洁长沙网站
2026/5/13 22:02:41 网站建设 项目流程
岳阳有哪几家做网站的,廉洁长沙网站,如何建设国外网站,微信公众号免费模板素材网站有时候任务是分不同人开发的#xff0c;如何把结果汇总到一个界面呢#xff1f; 或者有些好的类是自己封装后#xff0c;可以无限复制使用#xff0c;怎么挪到自己的主程序呢#xff1f; 以下举个小例子记录一下#xff0c;我也备份一下 说明#xff1a; 我有一个派生类…有时候任务是分不同人开发的如何把结果汇总到一个界面呢或者有些好的类是自己封装后可以无限复制使用怎么挪到自己的主程序呢以下举个小例子记录一下我也备份一下说明我有一个派生类继承于QWidget功能是用来绘制折线图的直接QT例子粘贴的还有一个主程序MainWindow里面有一个QWidget占位用来绘制折线图如何把折线图绘制的QWidget放置到主程序里面的QWidget呢继承类/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Charts module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:GPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 or (at your option) any later version ** approved by the KDE Free Qt Foundation. The licenses are as published by ** the Free Software Foundation and appearing in the file LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/#ifndefMAINWIDGET_H#defineMAINWIDGET_H#includeQtCharts/QChartGlobal#includeQtCharts/QChart#includeQtCharts/QChartView#includeQtWidgets/QWidget#includeQtWidgets/QGraphicsWidget#includeQtWidgets/QGridLayout#includeQtWidgets/QGraphicsGridLayout#includeQtWidgets/QDoubleSpinBox#includeQtWidgets/QGroupBox#includeQtCharts/QLineSeriesQT_CHARTS_USE_NAMESPACEclassMainWidget:publicQWidget{Q_OBJECTpublic:explicitMainWidget(QWidget*parent0);voidaddSeries();voidconnectMarkers();publicslots:voidremoveSeries();voiddisconnectMarkers();voidhandleMarkerClicked();private:QChart*m_chart;QListQLineSeries*m_series;QChartView*m_chartView;QGridLayout*m_mainLayout;QGridLayout*m_fontLayout;};#endif// MAINWIDGET_H/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Charts module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:GPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 or (at your option) any later version ** approved by the KDE Free Qt Foundation. The licenses are as published by ** the Free Software Foundation and appearing in the file LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/#includemainwidget.h#includeQtCharts/QChart#includeQtCharts/QChartView#includeQtWidgets/QPushButton#includeQtWidgets/QLabel#includeQtCore/QDebug#includeQtCharts/QLegend#includeQtWidgets/QFormLayout#includeQtCharts/QLegendMarker#includeQtCharts/QLineSeries#includeQtCharts/QXYLegendMarker#includeQtCore/QtMathQT_CHARTS_USE_NAMESPACEMainWidget::MainWidget(QWidget*parent):QWidget(parent){// Create chart view with the chartm_chartnewQChart();m_chartViewnewQChartView(m_chart,this);// Create layout for grid and detached legendm_mainLayoutnewQGridLayout();m_mainLayout-addWidget(m_chartView,0,1,3,1);setLayout(m_mainLayout);// Add few seriesaddSeries();addSeries();addSeries();addSeries();connectMarkers();// Set the title and show legendm_chart-setTitle(Legendmarker example (click on legend));m_chart-legend()-setVisible(true);m_chart-legend()-setAlignment(Qt::AlignBottom);m_chartView-setRenderHint(QPainter::Antialiasing);}voidMainWidget::addSeries(){QLineSeries*seriesnewQLineSeries();m_series.append(series);series-setName(QString(line QString::number(m_series.count())));// Make some sine wave for dataQListQPointFdata;intoffsetm_chart-series().count();for(inti0;i360;i){qreal xoffset*20i;data.append(QPointF(i,qSin(qDegreesToRadians(x))));}series-append(data);m_chart-addSeries(series);if(m_series.count()1)m_chart-createDefaultAxes();}voidMainWidget::removeSeries(){// Remove last series from chartif(m_series.count()0){QLineSeries*seriesm_series.last();m_chart-removeSeries(series);m_series.removeLast();deleteseries;}}voidMainWidget::connectMarkers(){//![1]// Connect all markers to handlerconstautomarkersm_chart-legend()-markers();for(QLegendMarker*marker:markers){// Disconnect possible existing connection to avoid multiple connectionsQObject::disconnect(marker,QLegendMarker::clicked,this,MainWidget::handleMarkerClicked);QObject::connect(marker,QLegendMarker::clicked,this,MainWidget::handleMarkerClicked);}//![1]}voidMainWidget::disconnectMarkers(){//![2]constautomarkersm_chart-legend()-markers();for(QLegendMarker*marker:markers){QObject::disconnect(marker,QLegendMarker::clicked,this,MainWidget::handleMarkerClicked);}//![2]}voidMainWidget::handleMarkerClicked(){//![3]QLegendMarker*markerqobject_castQLegendMarker*(sender());Q_ASSERT(marker);//![3]//![4]switch(marker-type())//![4]{caseQLegendMarker::LegendMarkerTypeXY:{//![5]// Toggle visibility of seriesmarker-series()-setVisible(!marker-series()-isVisible());// Turn legend marker back to visible, since hiding series also hides the marker// and we dont want it to happen now.marker-setVisible(true);//![5]//![6]// Dim the marker, if series is not visibleqreal alpha1.0;if(!marker-series()-isVisible())alpha0.5;QColor color;QBrush brushmarker-labelBrush();colorbrush.color();color.setAlphaF(alpha);brush.setColor(color);marker-setLabelBrush(brush);brushmarker-brush();colorbrush.color();color.setAlphaF(alpha);brush.setColor(color);marker-setBrush(brush);QPen penmarker-pen();colorpen.color();color.setAlphaF(alpha);pen.setColor(color);marker-setPen(pen);//![6]break;}default:{qDebug()Unknown marker type;break;}}}实现1.我原来不考虑主程序代码量、不考虑代码美观我都是直接写到主程序里面了但是这样代码太多了不方便管理所以要剥离出来单独封装2.在代码里面直接创建实例即可这样的话所有图标操作全部放到chart 实例中封装对应接口就行if(!ui-widget-layout()){ui-widget-setLayout(newQVBoxLayout());}chartnewMainWidget(this);// 添加到布局ui-widget-layout()-addWidget(chart);// 可选设置布局边距ui-widget-layout()-setContentsMargins(0,0,0,0);//调用的时候chart-addSeries();chart-connectMarkers();3.或者更简单在.ui中找到占位的QWidget 控件右键提升写类名和头文件即可后续调用就不需要代码了只需要ui-widget占位的控件调用派生类的接口函数就行ui-widget-addSeries();ui-widget-connectMarkers();可以了

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询