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. Have to give the command twice to perform a function
Qt 6.11 is out! See what's new in the release blog

Have to give the command twice to perform a function

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.4k 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.
  • T Offline
    T Offline
    thescouse
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Can you paste the relevent code ?

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thescouse
        wrote on last edited by
        #3

        @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();
        }

        }
        @

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          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 ?

          157

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thescouse
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

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

              157

              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