Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Old image stays when drawing new one
Qt 6.11 is out! See what's new in the release blog

Old image stays when drawing new one

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BobMarly
    wrote on last edited by
    #1

    i want my program to show a different drawing for every item in the combobox, and it does, but the previous drawing always stays when i choose the next item in the combobox, so eventually there are a lot of drawings, but i only want the one that i selected.
    @void MWidget::ChangeFile(int NewIndex)
    {
    if(NewIndex<airfoils.count())
    {
    ReadFile(airfoils.at(NewIndex));

        update();
    
    }
    

    }
    //![0]
    void MWidget::ReadFile(QString thefile)

    {
    m_File_p = new QFile (thefile);

    if (m_File_p != NULL)
    {
        if ( (m_File_p->exists() == true) &&
             (m_File_p->open(QIODevice::ReadOnly | QIODevice::Text) == true) )
        {
    
            QTextStream stream(m_File_p);
            QString line = stream.readLine();
    
            bool blnFirstLine =true;
            float flScale = 640;
            while (!line.isNull())
            {
    
                if(blnFirstLine)
                {
                    blnFirstLine=false;
                }else{
    
                    QStringList coordinates = line.split(",", QString::SkipEmptyParts );
    
                    if( coordinates.count() == 2 )
                    {
                        bool checkX;
                        float x = coordinates.at(0).trimmed().toFloat( &checkX )*flScale+100;
                        bool checkY;
                        float y = coordinates.at(1).trimmed().toFloat( &checkY )*(-1)*flScale+100;
    
                        if( checkX && checkY )
                            polyPoints  << QPointF(x,y);
                    }
                }
    
                line = stream.readLine();
    
    
            }
    
        }
        m_File_p->flush();
        m_File_p->close();
        delete  m_File_p;
    
    }
    

    }

    //![0]
    //![1]
    MWidget::~MWidget()
    {
    delete ui;

    }
    //![1]
    //![2]
    QSize MWidget::sizeHint() const
    {
    return QSize(840, 480);

    }
    //![2]
    //![3]
    void MWidget::paintEvent(QPaintEvent * event)
    {

    QWidget::paintEvent(event);
    

    setAttribute(Qt::WA_OpaquePaintEvent);
    // i found the QLabel idea online, but it doesnt seem to do anything
    QLabel *label = new QLabel(this);
    label->setAutoFillBackground(true);

    QPainter painter(this);
    
    painter.setRenderHint(QPainter::Antialiasing,true);
    QPen linepen(Qt::red);
    linepen.setCapStyle(Qt::RoundCap);
    linepen.setWidth(5);
    painter.setPen(linepen);
    

    painter.drawPolyline(polyPoints2);

    update();
    

    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      Something is not right, or your code is not complete:
      You stream into "polyPoints", but in paintEvent, you use "polyPoints2".

      Do you ever clear polyPoints?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BobMarly
        wrote on last edited by
        #3

        it was just a copying mistake, should be polypoints

        1 Reply Last reply
        0
        • O Offline
          O Offline
          onmouse
          wrote on last edited by
          #4

          it's seems like syntax?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            victim123
            wrote on last edited by
            #5

            dont know.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved