//Label.h-----------
#ifndef LABEL_H
#define LABEL_H
#include
#include
#include
#include
#include
#include
#include
#include
class MyItem:public QGraphicsItem
{
public:
MyItem(int m_x=0, int m_y=0, QString m_QSLabel="Label", int m_width=200, int m_height=50);
QRectF boundingRect()const;
void paint(QPainter * painter
, const QStyleOptionGraphicsItem * option
, QWidget * widget = 0);
private:
int m_x;
int m_y;
int m_width;
int m_height;
QString m_QSLabel;
};
#endif
//lable.cpp--------------
#include "label.h"
MyItem::MyItem(int x, int y, QString label, int width, int height ):m_x(x), m_y(y), m_QSLabel(label),m_width(width),m_height(height)
{
}
QRectF MyItem::boundingRect()const
{
return QRectF(0,0,100,100);
}
void MyItem::paint(QPainter painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
{
/*painter->setPen(QPen(Qt::black,5,Qt::DashDotDotLine,Qt::RoundCap));/
painter->setBrush(Qt::white);
painter->drawRect(m_x, m_y, m_width, m_height);
painter->drawLine(m_x, 50, m_x+80, 50);
QFont font("Arial",18);
painter->setFont(font);
QPoint *pPoint=new QPoint(m_x,m_y+32);
painter->setPen(QPen(Qt::red,30));
painter->drawText(*pPoint,m_QSLabel);
//----------------------------label完成------------------------------
QPoint start_pos(m_x+80,m_y+15);
QPoint end_pos(m_x+150,m_y+100);
QPainterPath path(start_pos);
QPoint c1((start_pos+end_pos).x()/2,start_pos.y());
QPoint c2((start_pos+end_pos).x()/2,end_pos.y());
path.cubicTo(c1,c2,end_pos);
painter->setPen(QPen(Qt::black,8));
painter->setBrush(QBrush(Qt::yellow,Qt::Dense7Pattern));
painter->drawPath(path);
}
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "label.h"
namespace Ui {
class mainwindow;
}
class mainwindow : public QWidget
{
Q_OBJECT
public:
explicit mainwindow(QWidget *parent = 0);
~mainwindow();
private:
Ui::mainwindow *ui;
QGraphicsScene *scene;
QGraphicsView *view;
};
#endif // MAINWINDOW_H
//mainwindow.cpp
//#include "menubar.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include "label.h"
//mianwindow中如何添加其他的控件??
mainwindow::mainwindow(QWidget *parent) : QWidget(parent)
,ui(new Ui::mainwindow)
{
setWindowFlags(Qt::FramelessWindowHint |Qt::WindowStaysOnTopHint);
scene = new QGraphicsScene;
//添加标签类
MyItem *itemA=new MyItem(150,0,"LabelA");
scene->addItem(itemA);
view = new QGraphicsView(scene);
view->setScene(scene);
view->resize(1024,768);
view->setWindowTitle("Godhand");
view->show();
}
mainwindow::~mainwindow()
{
delete ui;
}
//main.cpp
#include "mainwindow.h"
//#include "menubar.h"
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
mainwindow mainWindow;
return a.exec();
}
帮忙我看下 如何解决这个lnk2019和lnk1120的错误求下讲解过程