Have to give the command twice to perform a function



  • Hi everyone.
    I developed a function that draws a rectangle. It works just fine, takes the input from mouse events and all, but there is just this one quirk...I have to press the rectangle button on the toolbar twice to draw the rectangle. When I first click on the button and draw on the screen...nothing is visible. But when I press the button again the rectangle turns visible. Can anyone tel me what the problem can be?


  • Moderators

    Hi,

    Can you paste the relevent code ?



  • @void paint::drawrectangle()
    {@

    @ QPainter painter(&image);
    painter.setPen(QPen(PenColor, PenWidth, Qt::SolidLine, Qt::RoundCap,
    Qt::MiterJoin));@
    @painter.drawRect(rectangle);
    int rad = (PenWidth / 2) + 2;@
    @update(rectangle.normalized().adjusted(-rad, -rad, +rad, +rad));
    if(i==0)
    {
    ++i;
    drawrectangle();
    }

    }
    @


  • Moderators

    Sorry to say but i can't understand your code. Can you just explain what gets called when ? Also what is "rectangle" that you have passed to drawRect() ? Is i initialised to 0 before ?



  • @void ImageViewer::rectangle()
    {

    if(count == 0)
    {
        painter =  new paint;
        imageLabel->clear();
        setCentralWidget(painter);
        painter->openImage(file);
        count++;
    
    }
    painter->pen = false;
    painter->drawrectangle();
    

    }@

    Sorry, forgot this.


  • Moderators

    What is the "rectangle" in painter.drawRect(rectangle) ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.