用Qt绘制多边形

问题描述 投票:0回答:0

我是 Qt C++ 的新手。我想画一个三角形。但我面临太多错误。

不识别 poly 和 qpoint 以及 *e

我该如何解决这个问题?

#include "dialog.h"
#include "ui_dialog.h"
#include <QtCore>
#include <QtGui>
#include <QGraphicsScene>
#include <QGraphicsEllipseItem>
#include<qpainter.h>
#include<QPolygon>
#include<QPoint>
#include<QPainter>
#include<QPaintEvent>

Dialog::Dialog(int a1,int b1,int a2,int b2,int a3,int b3,char t,QWidget *parent):
QDialog(parent),

ui(new Ui::Dialog),
x1(a1),x2(a2),x3(a3),y1(b1),y2(b2),y3(b3),type(t)
{
ui->setupUi(this);
scene = new QGraphicsScene(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);

QBrush redBrush (Qt::red);
QPen blackpen(Qt::black);
blackpen.setWidth(1);
if(type=='c')
    ellipse = scene->addEllipse(0,0,10,10,blackpen,redBrush);
else if(type=='l')
{
    //draw line
}
else
{
    //draw traingle
    paintEvent(QPaintEvent *e);

error: 'e' 未在此范围内声明 }

}
void Dialog::paintEvent(QPaintEvent *e)
{
QPainter painter(this);

QPolygon poly;
poly «QPoint(100,150);

错误:程序中出现杂散的“�” 聚 « ;QPoint(120,130); ^ 聚 «QPoint(90,130); 聚 «QPoint(120,130);

          QPen linepen;
   linepen.setWidth(8);
   linepen.setColor(Qt::red);
   linepen.setJoinStyle(Qt::MiterJoin);
   painter.setPen(linepen);

   QBrush fillbrush;
   fillbrush.setColor(Qt::red);
   fillbrush.setStyle(Qt::SolidPattern);

   QPainterPath path;
   path.addPolygon(poly);

   painter.drawPolygon(poly);
   painter.fillPath(path,fillbrush);}


Dialog::~Dialog(){
delete ui;
}
c++ qt polygon
© www.soinside.com 2019 - 2024. All rights reserved.