QTCHART-QT official Drawing library installation and use

Source: Internet
Author: User

Brief introduction

QT Linear mapping control has the famous qwt,chartdirector, small and qcustomplot, of course, also has its own qtchart. For a long time Qtchart in the Qt family has been a toll module, only the commercial version can be used, but after Qt5.7 will open its permissions, see: Qt 5.7 Bright blind update. The following describes how to install Qtchart and make simple drawings.

Download

Download Qtchart here with Git, refer to QT Charts 5.7.0 installation Tutorial
If you still use Qt5.4 the following version please see, Qt5.4 below is not supported drip
Git address: https://github.com/qtproject/qtcharts.git

clone https://github.com/qtproject/qtcharts.git

After downloading the directory is this:


Download Perl:activeperl before you start compiling

Directly to the next point of installation.
You will need to restart your computer or manually activate the environment variables after the installation is complete.

Compiling Qtchart

This time with QT creator loading Qtcharts.pro

After a cup of tea time:

This is generated under the build directory:

Installation

After the compilation is complete, it can be installed.
Select QT Creator Project Bar-run tab-Add deployment Build

There is a need to add two deployments, one for Qtchart, and one for Qtchart documentation.
When you're done configuring, click Run

There will be a lot of replication information, it will copy the compiled DLL and header files to the QT installation directory

Open the Lib folder and the Include folder under the QT directory to see the Qtchart information that was copied over.
At this point, look at the Qtchart's build directory, more than the first time the compilation of a doc folder
You simply copy the Qtcharts folder and the Qtcharts.qch file in the Doc folder to the corresponding version folder in the Docs folder under the QT installation directory.

Then open QT assisant, search Qtchart, you can see the documentation!

At this point your Qtchart is mostly configured to complete.
There are also example installations, which can be found in the literature [3]

Test Qtchart

The following shows how to create a qtchart with a Qt creator interface designer, and other methods can be seen in the reference literature.
Create a new widget project first
Use a widget as a vector for the chart and place a widget on the interface


Right click on the widget to elevate the widget.


Elevate this widget to Qchartview

Qtchart has two types of drawing window containers, Qchart (Qpolarchart) and Qchartview, which differ from the official document description:

Qchart is a qgraphicswidget so can show in a qgraphicsscene. It manages the graphical representation of different types of the series and other chart related objects like legend and axes. If you simply want to show a chart in a layout, you can use the convenience class Qchartview instead of Qchart.

Qchartview is a standalone widget, can display charts. It does not require separate qgraphicsscene to work. If you want to display a chart of your existing qgraphicsscene, you need to use the Qchart (or Qpolarchart) class instead.

Because here is separate as a form placement, so with Qchartview

The promoted class is named Qchartview
Header file is also Qchartview, QT each class has a no suffix of the same name file, easy to include
An error occurs when trying to compile a program:

Official documentation shows that the pro file needs to be set up using Qtchart:

To create a simple application, start by creating a new QT Gui application project in QT Creator and add the . Pro file of the project:

QT += charts

In the main.cpp file, include the module headers and declare namespace usage:

#include <QtCharts>using namespace QtCharts;

wherein, alternative using QT_CHARTS_USE_NAMESPACE namespace qtcharts can be used;

Add the required content, compile or error, error location to Ui_widget

As I said before, the place where the qtchart is used needs to be included #include <QtCharts> as well as the namespace using namespace QtCharts; (or QT_CHARTS_USE_NAMESPACE instead of using namespace qtcharts;)
However, the Ui_widget file is automatically generated and can no longer be modified in this file, which is contained in a Widget.h called UI namespace, so

#include <QtCharts>QT_CHARTS_USE_NAMESPACE

Place on Widget.h:

#ifndef WIDGET_H#define WIDGET_H#include <QWidget>namespace Ui {class Widget;}class Widget : public QWidget{ Q_OBJECTpublic: explicit Widget(QWidget *parent = 0); ~Widget();private: Ui::Widget *ui;};#endif // WIDGET_H

At this point, you can compile:


In the constructor, add:

QLineSeries* line1 = new QLineSeries();for(double x=0;x<10;x+=0.1){ line1->append(x,sin(x));}QChart* c = new QChart();c->addSeries(line1);ui->chart->setChart(c);

The effect is as follows:

Summarize

When using the interface designer with Qtchart, you need to add the following on the corresponding interface header file:

#include <QtCharts>QT_CHARTS_USE_NAMESPACE

Otherwise, a compile error will occur!

Finish!

Reference documents

[1] Qt Charts 5.7.0 Installation Tutorial Http://www.jianshu.com/p/8d9a817aa6b9

[2] Qt Chart 5.7.0 Dummies Installation Tutorial http://www.cnblogs.com/findumars/p/5152294.html

[3] Qtcharts compilation (compilation Environment MSVC12) and VS2013 configuration Qtcharts http://blog.csdn.net/wokaowokaowokao12345/article/details/50933447

http://blog.csdn.net/czyt1988/article/details/51399341

QTCHART-QT official Drawing library installation and use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.