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


    Can you paste the relevent code ?

  • @void paint::drawrectangle()

    @ QPainter painter(&image);
    painter.setPen(QPen(PenColor, PenWidth, Qt::SolidLine, Qt::RoundCap,
    int rad = (PenWidth / 2) + 2;@
    @update(rectangle.normalized().adjusted(-rad, -rad, +rad, +rad));


  • 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;
    painter->pen = false;


    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.