添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
激动的单车  ·  Amazon ...·  5 月前    · 
逆袭的烈马  ·  python numpy array 空 ...·  10 月前    · 
温柔的桔子  ·  @RestControllerAdvice中 ...·  1 年前    · 

看Qt帮助文档 自学Qt---charts 动态画图 day4

打开例子,编译运行,前提你安装Qt的时候在kits中选择了Qt charts

项目结构

//mian.cpp

#include "chart.h"
#include <QtCharts/QChartView>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
QT_CHARTS_USE_NAMESPACE
int main(int argc, char *argv[])
    QApplication a(argc, argv);
    QMainWindow window;
    Chart *chart = new Chart;
    chart->setTitle("Dynamic spline chart");
    chart->legend()->hide();
    chart->setAnimationOptions(QChart::AllAnimations);
    QChartView chartView(chart);
    chartView.setRenderHint(QPainter::Antialiasing);
    window.setCentralWidget(&chartView);
    window.resize(400, 300);
    window.show();
    return a.exec();

常用单词

axis, shades, labels, and grid lines 
轴、阴影、标签和网格线
chart  n. 图表;海图;图纸;排行榜
   vt. 绘制…的图表;在海图上标出;

chart->legend()->hide(); 

void QGraphicsItem::hide()

Hides the item (items are visible by default)

This convenience function is equivalent to calling setVisible(false)

See also show () and setVisible ()

隐藏项(默认情况下项是可见的)。

这个方便的函数相当于调用setVisible(false)。

参见show()和setVisible()。


Q Legend *QChart::legend() const

Returns the legend object of the chart. Ownership stays with the chart.

返回chart的图例对象。所有权与图表保持一致

legend
n. 传奇;说明;图例;刻印文字
传奇嘛 肯定是大家的典范 所以就有图例的意思了  (盲猜的)
stays with  保持与。。

void QGraphicsItem::setVisible(bool visible)

If visible is true, the item is made visible . Otherwise, the item is made invisible.

如果“可见”为真,则该项目(对象)将变为可见。否则,项目将不可见。

Invisible items are not painted, nor do they receive any events.

不可见的项目不会被绘制,也不会接收任何事件。

Items are visible by default; it is unnecessary to call setVisible() on a new item.

项目默认可见;没有必要在新项上调用setVisible()。

Note : An item with opacity set to 0 will still be considered visible, although it will be treated like an invisible item: mouse events will pass through it, it will not be included in the items returned by QGraphicsView::items(), and so on. However, the item will retain the focus.

注意:不透明度设置为0的项目仍然被认为是可见的,尽管它将被视为不可见的项目:鼠标事件将通过它,它将不会包括在QGraphicsView::items()返回的项目中,等等。然而,该项目将保持焦点。

visible
opacity 

chart->setAnimationOptions(QChart::AllAnimations);
//All animation types are enabled in the chart. 
//chart中启用了所有动画类型。

animationOptions : QChart::AnimationOptions

This property holds the animation options for the chart.

Animations are enabled or disabled based on this setting.

此属性保存图表的动画选项。

动画可以根据此设置启用或禁用。

property  性能 财产 所有权 属性
holds   v. 把握(hold的第三人称单数);保存
        n. 保留(hold的复数)
Animations  动画


QChart::NoAnimation

Animation is disabled in the chart. This is the default value.

QChart::GridAxisAnimations

Grid axis animation is enabled in the chart.

QChart::SeriesAnimations

Series animation is enabled in the chart.

QChart::AllAnimations

All animation types are enabled in the chart.


QChartView chartView(chart);

QChartView Class

The QChartView is a standalone widget that can display charts.

这个部件可以显示 charts (相当于画画的纸容器)


chartView.setRenderHint(QPainter::Antialiasing);
//消除锯齿

void QGraphicsView::setRenderHint( QPainter::RenderHint hint , bool enabled = true)

If enabled is true, the render hint hint is enabled; otherwise it is disabled.

如果启用为真,则渲染提示启用;否则它将被禁用。

render  渲染 给予
n. 暗示;线索
vt. 暗示;示意

QPainter::Antialiasing

Indicates that the engine should antialias edges of primitives if possible.

指示引擎应尽可能消除原语的边缘锯齿。

Indicates   表明 显示 指示
primitives
n. [计] 基元(primitive的复数);原始事物;基本体

这样,main.cpp也就看完了,养成看帮助文档的好习惯,以后自学什么都不是难题,在百度,在其他看的都是别人的理解,有官方文档为什么不看呢?

之前就对exec()函数好奇,就是知道类似事件循环,这次就趁机会了解一下吧

什么是事件循环,听重要的,尤其在ui编程,要是没有时间循环可能界面就显示一瞬间然后立马消失, 可以去搜搜,我理解的也不好就不说了,以免误导


[static] int QApplication::exec()

Enters the main event loop and waits until exit () is called, then returns the value that was set to exit () (which is 0 if exit () is called via quit ()).

进入 主事件循环 并等待,直到调用exit(),然后返回设置为exit()的值(如果通过quit()调用exit(),则该值为0)。

Enters  进入
event loop   事件循环

It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.

有必要 调用此函数来启动事件处理 主事件循环从窗口系统接收事件,并将这些事件分派给应用程序小部件。

dispatches  分派

Generally, no user interaction can take place before calling exec(). As a special case , modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.

一般来说,在调用exec()之前不会发生任何用户交互。作为一种特殊情况,像QMessageBox这样的模态小部件可以在调用exec()之前使用,因为模态小部件调用exec()来启动本地事件循环。

user interaction   用户交互
take place  发生
As a special case  作为一个特殊的情况

To make your application perform idle processing , executing a special function whenever there are no pending events , use a QTimer with 0 timeout. More advanced idle processing schemes can be achieved using processEvents ().

要使应用程序执行空闲处理,在没有挂起事件时执行一个特殊函数时,请使用 QTimer with 0 timeout的QTimer。可以使用processEvents()实现更高级的空闲处理方案。

idle    
adj. 闲置的;懒惰的;停顿的
vt. 虚度;使空转
perform  执行