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. Recurcive repaint problem

Recurcive repaint problem

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 3.3k Views
  • 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.
  • V Offline
    V Offline
    Vyivrain
    wrote on 24 Jun 2014, 20:38 last edited by
    #3

    If it was so obvious, I wouldn't post this question.Just to correct this question, my error comes, when I click on any button. If you can see the code, there're no ways to compute geom.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 24 Jun 2014, 20:50 last edited by
      #4

      Please describe a bit mor,when this occures.
      At startup? After doing what?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vyivrain
        wrote on 24 Jun 2014, 20:58 last edited by
        #5

        The app starts nicely, but when I try to press any button this stuff happens. If you want the app is on github you can download hole project there. I think the hole problem is mouseEvent and paintEvent, because f.e. rectButtonClicked, ellButtonClicked, lineButtonClicked is only assure, that only one button is active( checked ) at a time. And another methods are just for initialization.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on 24 Jun 2014, 21:01 last edited by
          #6

          Hi,

          I just started the programin the debugger.
          what fails is:

          @
          void MyPaint::paintEvent(QPaintEvent *pe)
          {
          QPainter painter( this );
          if( lineButClicked )
          {
          painter.drawLine( geom[index][0], geom[index][1] ); //<-- here
          index++;
          pointsNum = 0;
          }
          @

          geom has size 1, geom[0] has size 0, but you access elements of it.

          you activate the sections inpaint with clicking the button. But the geom vector does contain an empty vector.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vyivrain
            wrote on 24 Jun 2014, 21:03 last edited by
            #7

            Okay, I just don't understand why it repaints , when I press the button.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on 24 Jun 2014, 21:07 last edited by
              #8

              But your code hasmor problems.
              You are painting on the dialog, not on the view for example.

              @
              void MyPaint::paintEvent(QPaintEvent *pe)
              {
              QPainter painter( this );
              painter.setPen(Qt::red);
              if( lineButClicked )
              {
              if(geom[index].size() >= 2)
              {
              painter.drawLine( geom[index][0], geom[index][1] );
              index++;
              pointsNum = 0;
              }
              }
              else if( ellButClicked )
              {
              if(geom[index].size() >= 2)
              {
              painter.drawRect( QRect( geom[index][0], geom[index][1] ) );
              index++;
              pointsNum = 0;
              }
              }
              else if ( rectButClicked )
              {
              if(geom[index].size() >= 2)
              {
              painter.drawEllipse( QRect( geom[index][0], geom[index][1] ) );
              index++;
              pointsNum = 0;
              }
              }
              }

              @

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on 24 Jun 2014, 21:09 last edited by
                #9

                [quote author="Vyivrain" date="1403643808"]Okay, I just don't understand why it repaints , when I press the button.[/quote]

                it may repaint whenever it wants. Maybe due to the cursor change.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  Vyivrain
                  wrote on 24 Jun 2014, 21:13 last edited by
                  #10

                  Yeah, I know, but I can't paint on the dialog, because I have a condition in mouseEvent. But the main thing is repaint. How ca I deal with it, so it will repaint only, when mouseEvent occurs and there I'll use update to launch paintEvent. And because I didn't know that repaint calls whenever it wants , it became obvious error, my bad =(.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Vyivrain
                    wrote on 24 Jun 2014, 21:39 last edited by
                    #11

                    Okay, did that with another if statement. But , I can paint on the just if I do QPainter( view ) correct? Nevermind, did that too.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on 26 Jun 2014, 16:16 last edited by
                      #12

                      You have to overwrite the paint event of the widget, where you want to paint in.
                      You subclassed the dialog, hence you draw in the dialog.

                      @
                      void MyPaint::paintEvent(QPaintEvent *pe)
                      @

                      MyPaint is the dialog...

                      [quote author="Vyivrain" date="1403644402"]Yeah, I know, but I can't paint on the dialog, because I have a condition in mouseEvent. But the main thing is repaint. How ca I deal with it, so it will repaint only, when mouseEvent occurs and there I'll use update to launch paintEvent. And because I didn't know that repaint calls whenever it wants , it became obvious error, my bad =(.[/quote]

                      Repaints can also occure, if yomeone puts a window in front of yours and away again, there are many reasons.

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      1 Reply Last reply
                      0

                      12/12

                      26 Jun 2014, 16:16

                      • Login

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