QT paintEvent 中的一个int值 怎么通过图形界面输入?

就是下面的n值,先谢谢大佬们了

 void MainWindow::paintEvent(QPaintEvent *)
{
    int D=5;
    int n;//这个值
    point *p=new point[n];
    QPainter painter(this);
    QPen pen;
    pen.setColor(Qt::blue);
    pen.setWidth(6);
    painter.setPen(pen);
    QPointF *pointf=new QPointF [n];
    srand((unsigned int)(time(0)));
    for (int i=0; i<n; ++i)
    {
        p[i].x=rand()%1000+1;
        p[i].y=rand()%1000+1;
        pointf[i].setX(p[i].x);
        pointf[i].setY(p[i].y);
    }
    painter.drawPoints(pointf, n);
    point ans[2];
    double dismin1 = closestpoint(p, n, ans[0], ans[1]);
    double dismin2 = closestpointBF(p,n);
    pen.setColor(Qt::red);
    pen.setWidth(4);
    painter.setPen(pen);
    painter.drawLine(ans[0].x,ans[0].y,ans[1].x,ans[1].y);
    std::string str1="The shortest distance is "+std::to_string(dismin1)+"   glass state:broken    point1:("+std::to_string(ans[0].x)+","+std::to_string(ans[0].y)+")  point2:("+std::to_string(ans[1].x)+","+std::to_string(ans[1].y)+")";
    std::string str2="The shortest distance is "+std::to_string(dismin1)+"   glass state:not broken    point1:("+std::to_string(ans[0].x)+","+std::to_string(ans[0].y)+")  point2:("+std::to_string(ans[1].x)+","+std::to_string(ans[1].y)+")";
    std::string str3="Brute Force:"+std::to_string(dismin2)+"   Divide&Conquer:"+std::to_string(dismin1);
    QString qstr1 = QString::fromStdString(str1);
    QString qstr2 = QString::fromStdString(str2);
    QString qstr3 = QString::fromStdString(str3);
    if(dismin1<D)
        painter.drawText(150, 1050, qstr1);
    else
        painter.drawText(150, 1050, qstr2);
    painter.drawText(350, 1075, qstr3);
    //delete []p;
}

查看全部
u013382064
DaDiao444
2018/11/13 14:08
  • qt
  • 点赞
  • 收藏
  • 回答
    私信

1个回复