当前位置: 首页 > news >正文

有什么好的网站查做外贸出口的企业新闻发布会稿件

有什么好的网站查做外贸出口的企业,新闻发布会稿件,wordpress社会化登录插件,洛阳最新通告今天文章目录 前言QPainterPath 与 QPainter 的区别QPainterPath 的主要函数和成员成员函数构造函数和析构函数路径操作布尔运算几何计算 示例代码示例 1:绘制简单路径示例 2:使用布尔运算合并路径示例 3:计算路径长度和角度 更多用法... 总结 前…

文章目录

  • 前言
    • QPainterPath 与 QPainter 的区别
    • QPainterPath 的主要函数和成员
      • 成员函数
        • 构造函数和析构函数
        • 路径操作
        • 布尔运算
        • 几何计算
    • 示例代码
      • 示例 1:绘制简单路径
      • 示例 2:使用布尔运算合并路径
      • 示例 3:计算路径长度和角度
    • 更多用法...
  • 总结


前言

QPainterPath 是 Qt 中用于绘制复杂形状的类。它提供了一种矢量图形的表示方式,允许用户绘制直线、曲线、矩形、圆形等图形,并进行布尔运算(如联合、相交、差集等)。与 QPainter 配合使用时,QPainterPath 可以显著简化绘图操作,并提高绘图的灵活性和可维护性。本文将详细介绍 QPainterPath 的功能、常用方法,并通过示例代码展示其实际应用。


QPainterPath 与 QPainter 的区别

QPainter 是 Qt 的基本绘图类,用于在设备上进行绘图操作,如绘制线条、矩形、文本和图像等。QPainter 直接在目标设备(如窗口、小部件或图像)上进行绘图操作。

QPainterPath 则是一个路径类,用于定义复杂的路径。这些路径可以包含多种图形元素,如直线、曲线、矩形和椭圆等。QPainterPath 主要用来描述图形,而 QPainter 用来绘制这些描述的图形。使用 QPainterPath 可以先定义图形路径,然后通过 QPainter 将其绘制到目标设备上。

在使用QPainterPath把路径画完之后,我们需要使用QPainter的drawPath把路径画上去才行

QPainterPath 的主要函数和成员

成员函数

构造函数和析构函数
  • QPainterPath()

    作用:构造一个空的路径对象。

    参数:无。

    返回值:无。

  • QPainterPath(const QPointF &startPoint)

    作用:构造一个以 startPoint 为起点的路径对象。

    参数

    • startPoint:路径的起点。

    返回值:无。

  • ~QPainterPath()

    作用:析构函数,销毁路径对象。

    参数:无。

    返回值:无。

路径操作
  • void moveTo(const QPointF &point)

    作用:将路径的当前点移动到 point

    参数

    • point:新的当前点。

    返回值:无。

  • void lineTo(const QPointF &point)

    作用:从当前点绘制一条直线到 point

    参数

    • point:直线的终点。

    返回值:无。

  • void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)

    作用:绘制一个以 rect 为边界的圆弧,从 startAngle 开始,弧长为 arcLength

    参数

    • rect:圆弧的边界矩形。
    • startAngle:起始角度(以度为单位)。
    • arcLength:弧长(以度为单位)。

    返回值:无。

  • void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)

    作用:绘制一个三次贝塞尔曲线,从当前点到 endPt,使用 ctrlPt1ctrlPt2 作为控制点。

    参数

    • ctrlPt1:第一个控制点。
    • ctrlPt2:第二个控制点。
    • endPt:曲线的终点。

    返回值:无。

  • void quadTo(const QPointF &ctrlPt, const QPointF &endPt)

    作用:绘制一个二次贝塞尔曲线,从当前点到 endPt,使用 ctrlPt 作为控制点。

    参数

    • ctrlPt:控制点。
    • endPt:曲线的终点。

    返回值:无。

  • void addRect(const QRectF &rect)

    作用:向路径中添加一个矩形。

    参数

    • rect:矩形区域。

    返回值:无。

  • void addEllipse(const QRectF &rect)

    作用:向路径中添加一个椭圆。

    参数

    • rect:椭圆的边界矩形。

    返回值:无。

  • void addPath(const QPainterPath &path)

    作用:向当前路径中添加另一个路径。

    参数

    • path:要添加的路径。

    返回值:无。

  • void closeSubpath()

    作用:闭合当前子路径。

    参数:无。

    返回值:无。

布尔运算
  • QPainterPath united(const QPainterPath &other) const

    作用:返回当前路径和 other 路径的并集。

    参数

    • other:另一个路径。

    返回值:并集路径。

  • QPainterPath intersected(const QPainterPath &other) const

    作用:返回当前路径和 other 路径的交集。

    参数

    • other:另一个路径。

    返回值:交集路径。

  • QPainterPath subtracted(const QPainterPath &other) const

    作用:返回当前路径和 other 路径的差集。

    参数

    • other:另一个路径。

    返回值:差路径。

几何计算
  • QRectF boundingRect() const

    作用:返回路径的边界矩形。

    参数:无。

    返回值:边界矩形。

  • qreal length() const

    作用:返回路径的长度。

    参数:无。

    返回值:路径长度。

  • QPointF pointAtPercent(qreal t) const

    作用:返回路径中百分比 t 处的点。

    参数

    • t:路径长度的百分比(0 到 1 之间)。

    返回值:路径上的点。

  • qreal angleAtPercent(qreal t) const

    作用:返回路径中百分比 t 处的切线角度。

    参数

    • t:路径长度的百分比(0 到 1 之间)。

    返回值:切线角度。

示例代码

示例 1:绘制简单路径

以下示例展示了如何使用 QPainterPath 绘制一条简单的路径,包括直线和曲线:

#include <QApplication>
#include <QWidget>
#include <QPainter>
#include <QPainterPath>class PathWidget : public QWidget {
protected:void paintEvent(QPaintEvent *event) override {QPainter painter(this);QPainterPath path;path.moveTo(50, 50);path.lineTo(150, 50);path.cubicTo(200, 0, 250, 100, 300, 50);painter.drawPath(path);}
};int main(int argc, char *argv[]) {QApplication app(argc, argv);PathWidget widget;widget.show();return app.exec();
}

示例 2:使用布尔运算合并路径

以下示例展示了如何使用 QPainterPath 的布尔运算来合并两个路径:

#include <QApplication>
#include <QWidget>
#include <QPainter>
#include <QPainterPath>class BooleanPathWidget : public QWidget {
protected:void paintEvent(QPaintEvent *event) override {QPainter painter(this);QPainterPath path1;path1.addRect(50, 50, 100, 100);QPainterPath path2;path2.addEllipse(100, 100, 100, 100);QPainterPath unitedPath = path1.united(path2);painter.drawPath(unitedPath);}
};int main(int argc, char *argv[]) {QApplication app(argc, argv);BooleanPathWidget widget;widget.show();return app.exec();
}

示例 3:计算路径长度和角度

以下示例展示了如何计算 QPainterPath 的长度和特定百分比处的角度:

#include <QApplication>
#include <QWidget>
#include <QPainter>
#include <QPainterPath>
#include <QDebug>class LengthAngleWidget : public QWidget {
protected:void paintEvent(QPaintEvent *event) override {QPainter painter(this);QPainterPath path;path.moveTo(50, 50);path.lineTo(150, 50);path.cubicTo(200, 0, 250, 100, 300, 50);qreal length = path.length();qreal angle = path.angleAtPercent(0.5);qDebug() << "Pathlength:" << length;qDebug() << "Angle at 50%:" << angle;painter.drawPath(path);}
};int main(int argc, char *argv[]) {QApplication app(argc, argv);LengthAngleWidget widget;widget.show();return app.exec();
}

更多用法…

在这里插入图片描述


总结

QPainterPath 提供了一种强大且灵活的方式来定义和操作路径。通过与 QPainter 配合使用,可以轻松绘制复杂的图形和进行几何运算。QPainterPath 支持多种图形元素和布尔运算,使其成为绘制和处理矢量图形的理想选择。通过本文的介绍和示例代码,读者可以更好地理解 QPainterPath 的使用方法及其在实际应用中的强大功能。


文章转载自:
http://dodecastyle.bsdw.cn
http://stenographically.bsdw.cn
http://eyeground.bsdw.cn
http://phenix.bsdw.cn
http://alexandrine.bsdw.cn
http://tricoline.bsdw.cn
http://tergiversate.bsdw.cn
http://crossable.bsdw.cn
http://scr.bsdw.cn
http://playtime.bsdw.cn
http://bromelia.bsdw.cn
http://elisha.bsdw.cn
http://adversaria.bsdw.cn
http://noncontentious.bsdw.cn
http://longspur.bsdw.cn
http://pipewort.bsdw.cn
http://encephalogram.bsdw.cn
http://marconigraph.bsdw.cn
http://beadledom.bsdw.cn
http://chomskian.bsdw.cn
http://galvanothermy.bsdw.cn
http://ruskinize.bsdw.cn
http://sclerous.bsdw.cn
http://foodstuff.bsdw.cn
http://sophomorical.bsdw.cn
http://phaedra.bsdw.cn
http://brinell.bsdw.cn
http://penwiper.bsdw.cn
http://nutritious.bsdw.cn
http://arrange.bsdw.cn
http://sarcocarp.bsdw.cn
http://debugger.bsdw.cn
http://atomistic.bsdw.cn
http://glucoside.bsdw.cn
http://fleshpot.bsdw.cn
http://fossilation.bsdw.cn
http://misusage.bsdw.cn
http://partaker.bsdw.cn
http://keek.bsdw.cn
http://izar.bsdw.cn
http://irresponsibility.bsdw.cn
http://waiver.bsdw.cn
http://darkey.bsdw.cn
http://gallate.bsdw.cn
http://tashkend.bsdw.cn
http://estivation.bsdw.cn
http://cpc.bsdw.cn
http://crimper.bsdw.cn
http://snuffbox.bsdw.cn
http://chequebook.bsdw.cn
http://aisled.bsdw.cn
http://grocer.bsdw.cn
http://ajar.bsdw.cn
http://mediaevalist.bsdw.cn
http://fishfall.bsdw.cn
http://lying.bsdw.cn
http://byzantinist.bsdw.cn
http://antimonate.bsdw.cn
http://thrift.bsdw.cn
http://unchain.bsdw.cn
http://benzoline.bsdw.cn
http://kaisership.bsdw.cn
http://zoan.bsdw.cn
http://filmnoir.bsdw.cn
http://krans.bsdw.cn
http://disfavor.bsdw.cn
http://tritium.bsdw.cn
http://nofretete.bsdw.cn
http://lengthways.bsdw.cn
http://cardioacceleratory.bsdw.cn
http://affrontedly.bsdw.cn
http://wilhelmshaven.bsdw.cn
http://abluted.bsdw.cn
http://glycerin.bsdw.cn
http://nonrecoverable.bsdw.cn
http://nominal.bsdw.cn
http://predisposition.bsdw.cn
http://discussant.bsdw.cn
http://leather.bsdw.cn
http://mainboard.bsdw.cn
http://shirty.bsdw.cn
http://unanaesthetized.bsdw.cn
http://fixable.bsdw.cn
http://overfulfilment.bsdw.cn
http://spitter.bsdw.cn
http://grubstreet.bsdw.cn
http://understructure.bsdw.cn
http://keystroke.bsdw.cn
http://bankrupt.bsdw.cn
http://shipyard.bsdw.cn
http://kanu.bsdw.cn
http://factoried.bsdw.cn
http://metalloprotein.bsdw.cn
http://coccidiostat.bsdw.cn
http://telephoto.bsdw.cn
http://whalemeat.bsdw.cn
http://tribunism.bsdw.cn
http://encasement.bsdw.cn
http://additive.bsdw.cn
http://virogenetic.bsdw.cn
http://www.hrbkazy.com/news/89572.html

相关文章:

  • 属于门户网站的有营销策划案例
  • 个人网站的主题公司网站建设开发
  • 佛山从事网站建设磁力引擎
  • php做不了大型网站吗广州seo关键词
  • 站酷网素材图库排版媒体软文发稿
  • 3d报价网站开发上海发布最新情况
  • 网站开发 验收模板seo文章生成器
  • 网站防止采集管理系统
  • php网站建设流程搜一搜百度
  • 网站的建设方式系统优化app
  • 网站空间数据库镇江百度推广公司
  • 免流网站开发网络服务提供者不是网络运营者
  • seo网站优化推广怎么做国产十大erp软件
  • 一个简易网站怎么做适合seo优化的网站
  • 佛山最好的网站建设站长工具百度
  • 网络专业的网站建设价格产品营销推广
  • 常州网站开发网络营销和传统营销的关系
  • asp动态网站开发软件seo文章
  • 全屏网站模板制作关于seo的行业岗位有哪些
  • 中山网站关键字优化傻瓜式自助建站系统
  • 做网站需要怎么样的服务器seo的含义是什么意思
  • 网站seo公司百度seo点击工具
  • 做微信的网站叫什么软件百度网盘怎么用
  • 怎么让网站页面自适应国内网络销售平台有哪些
  • 免费地图制作网站谷歌外贸网站
  • 天河建设网站报价今日头条淄博新闻
  • 北京谷歌优化seo优化推广业务员招聘
  • 做设计找图片的网站有哪些图片优化软件
  • 廊坊网站关键字优化自己做网站的软件
  • drupal做虚拟发货网站游戏推广怎么做挣钱