效果如下图
void MainWidget::draw_Direction() { QPainter painter1(ui->label_Direction); painter1.setRenderHint(QPainter::Antialiasing,true); painter1.setPen(QPen(QColor(Qt::blue),1.5,Qt::SolidLine,Qt::FlatCap)); /* * move point QTransform t_y; t_y.rotate(-90,Qt::YAxis); painter1.setTransform(t_y); int temp =30; QTransform t_z; t_z.rotate(temp,Qt::ZAxis); painter1.setTransform(t_z); painter1.translate(0+135*qCos(30*PI/180.0),0-135*qSin(30*PI/180.0)); painter1.translate(0-39+96,0-39-96); painter1.translate((0-(((135/(qCos(45*PI/180.0)))*qSin((temp+45)*PI/180.0)-135)*(qSin(temp*PI/180.0)))+(135-((135/(qCos(45*PI/180.0)))*qCos((temp+45)*PI/180.0)))),((0-(((135/(qCos(45*PI/180.0)))*qSin((temp+45)*PI/180.0)-135)*(qCos(temp*PI/180.0))))-(135-((135/(qCos(45*PI/180.0)))*qSin((temp+45)*PI/180.0))))); painter1.translate(0-((TEMP_R*qSin((temp+45)*PI/180.0))-135)*qCos((temp)*PI/180.0)+(TEMP_R*qCos((temp)*PI/180.0))* qCos((temp)*PI/180.0),0-((TEMP_R*qSin((temp+45)*PI/180.0))-135)*qSin((temp)*PI/180.0)-(TEMP_R*qCos((temp)*PI/180.0))* qSin((temp)*PI/180.0)); qDebug()<<(TEMP_R*qCos((temp)*PI/180.0))* qSin((temp)*PI/180.0); */ painter1.translate(135,135); painter1.save(); painter1.rotate(num_Angle); for(int i = 0;i<360;) { if((i%90) == 0) { painter1.drawLine(0+(95*qSin(i*PI/180.0)),0-(95*qCos(i*PI/180.0)),0+(100*qSin(i*PI/180.0)),0-(100*qCos(i*PI/180.0))); i=i+30; } painter1.drawLine(0+(95*qSin(i*PI/180.0)),0-(95*qCos(i*PI/180.0)),0+(110*qSin(i*PI/180.0)),0-(110*qCos(i*PI/180.0))); i=i+30; } for(int j = 0;j<360;) { if((j%30) == 0 || (j%90) == 0) { j= j+10; } painter1.drawLine(0+(100*qSin(j*PI/180.0)),0-(100*qCos(j*PI/180.0)),0+(110*qSin(j*PI/180.0)),0-(110*qCos(j*PI/180.0))); j=j+10; } painter1.setPen(QPen(QColor(Qt::blue),3,Qt::SolidLine,Qt::FlatCap)); QRect rect1(-7,-113,15,15); QRect rect1_1(-7,-95,15,15); QRect rect2(-112,-9,15,15); QRect rect3(-7,103,15,15); QRect rect4(100,-9,15,15); QString str_N = "N"; QString str_S = "S"; QString str_W = "W"; QString str_E = "E"; QFont font("宋体",16,QFont::Bold); painter1.setFont(font); painter1.drawText(rect1,Qt::AlignCenter,str_N); painter1.drawText(rect2,Qt::AlignCenter,str_W); painter1.drawText(rect3,Qt::AlignCenter,str_S); painter1.drawText(rect4,Qt::AlignCenter,str_E); QPixmap pixmap_pointer; pixmap_pointer.load(":/Global/Source/Global/Pointer.png"); painter1.drawPixmap(rect1_1,pixmap_pointer); painter1.restore(); QRect rect_pixmap(-15,-15,30,30); QPixmap pixmap_plane; pixmap_plane.load(":/Global/Source/Global/Plane.png"); painter1.drawPixmap(rect_pixmap,pixmap_plane); }
至于好多人不知道怎么在Lable上面绘图,可以参考我以前写的