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. Resizing mainwindow using resizeEvent works very slow
Forum Updated to NodeBB v4.3 + New Features

Resizing mainwindow using resizeEvent works very slow

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 3 Posters 11.5k Views 2 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.
  • ? A Former User

    @kshegunov said:

    If you want a "realtime" behavior, then thread the IO!

    And ow can I do that?

    I have tried calling only the function to calculate (x, y) without calling drawPath() in resizeEvent() something like this

    path->calculatedXY(someVector, width, height);
    

    but it gives me Runtime Error and "index out of range" for the vector used in that function.

    kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by kshegunov
    #14

    @soloespresso said:

    And ow can I do that?

    Look here for an introduction.

    but it gives me Runtime Error and "index out of range" for the vector used in that function.

    See @jsulm's explanation as to why this is happening.
    Additionally your for loop is wrong:

    for (int i = 0; i < someX.size()-1; i++)  {
    

    this skips the last element in the vector.

    Kind regards.

    Read and abide by the Qt Code of Conduct

    ? 1 Reply Last reply
    0
    • jsulmJ jsulm

      @soloespresso readPosition() does not set someVector!
      If the change frequency of the file is so low then you should not read it all the time - it's just wasted time. You can use QFileSystemWatcher class to detect changes in this file and then reread it.

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #15

      @jsulm

      @jsulm said:

      @soloespresso readPosition() does not set someVector!

      I have some other functions in between. The readPosition() I posted is to give an idea what readPosition() does which is extract the data and keep them in a vector.

      If the change frequency of the file is so low then you should not read it all the time - it's just wasted time. You can use QFileSystemWatcher class to detect changes in this file and then reread it.

      OK, I will take a look on that.

      1 Reply Last reply
      0
      • kshegunovK kshegunov

        @soloespresso said:

        And ow can I do that?

        Look here for an introduction.

        but it gives me Runtime Error and "index out of range" for the vector used in that function.

        See @jsulm's explanation as to why this is happening.
        Additionally your for loop is wrong:

        for (int i = 0; i < someX.size()-1; i++)  {
        

        this skips the last element in the vector.

        Kind regards.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #16

        @kshegunov said:

        @soloespresso said:

        And ow can I do that?

        Look here for an introduction.

        Ok, I will take a look.

        but it gives me Runtime Error and "index out of range" for the vector used in that function.

        See @jsulm's explanation as to why this is happening.
        Additionally your for loop is wrong:

        for (int i = 0; i < someX.size()-1; i++)  {
        

        this skips the last element in the vector.

        Kind regards.

        Right!!! I didn't see it. Thank you.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #17
          for (int i = 0; i < someX.size()-1; i++)  {
          

          fix this but still Runtime Error and "index out of range".

          I will check QFileSystemWatcher and thread after.

          kshegunovK 1 Reply Last reply
          0
          • ? A Former User
            for (int i = 0; i < someX.size()-1; i++)  {
            

            fix this but still Runtime Error and "index out of range".

            I will check QFileSystemWatcher and thread after.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #18

            @soloespresso

            fix this but still Runtime Error and "index out of range".

            This hasn't anything to do with your error, it was just an observation. As to the assertion (which I'm assuming your code is failing), you should track that in the debugger.

            Read and abide by the Qt Code of Conduct

            ? 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @soloespresso

              fix this but still Runtime Error and "index out of range".

              This hasn't anything to do with your error, it was just an observation. As to the assertion (which I'm assuming your code is failing), you should track that in the debugger.

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #19

              @kshegunov said:

              @soloespresso

              fix this but still Runtime Error and "index out of range".

              This hasn't anything to do with your error, it was just an observation. As to the assertion (which I'm assuming your code is failing), you should track that in the debugger.

              So let me make sure if what I am doing is ok for Qt.
              I have drawPath() in QWidget.

              void DrawPath::drawPath(QString inFile, QString outFile, float width, float height)
              {
                  readPosition(inFile);
                  calculatedXY(someVector, width, height);
                  writePosition(outFile, latLongPointVector);
              }
              

              Can I call calculatedXY(someVector, width, height); outside drawPath() in resizeEvent() like this?

              void MainWindow::resizeEvent(QResizeEvent *event)
              {
              
                  //scaled window size
                  scaledWidth = double(event->size().width())/360.0;
                  scaledHeight = double(event->size().height())/180.0;
              
                  //QString inFile = ":/input.txt";
                  //QString outFile = "output.txt";
              
                  //set label window size
                  ui->label->setGeometry(0, 0, 360*scaledWidth, 180*scaledHeight);
              
                  //set draworbit window size
                  //path->drawPath(inFile, outFile, scaledWidth, scaledHeight);
                  path->calculatedXY(someVector, scaledWidth, scaledHeight);
                  path->setGeometry(0, 0, 360*scaledWidth, 180*scaledHeight);
              }
              
              1 Reply Last reply
              0
              • kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #20

                @soloespresso
                No one is preventing you from calling calculatedXY(), but if it's a good design choice really depends what that function actually does.

                Read and abide by the Qt Code of Conduct

                ? 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  @soloespresso
                  No one is preventing you from calling calculatedXY(), but if it's a good design choice really depends what that function actually does.

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #21

                  @kshegunov said:

                  @soloespresso
                  No one is preventing you from calling calculatedXY(), but if it's a good design choice really depends what that function actually does.

                  Thank you for the confirmation.
                  Because calling drawPath() will call readPosition(), calculatedXY() and writePosition(), calling calculatedXY() directly will prevent resizeEvent() to reread the text file.

                  But this give me that Runtime Error and "index out of range" which I will debug later.

                  Now the problem is how to draw the line? I use paintEvent() to draw a line and the function is called when drawPath() is called.

                  1 Reply Last reply
                  0
                  • jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #22

                    "Now the problem is how to draw the line?" - what is the problem with that? When paintEvent() is called you draw the line.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    ? 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      "Now the problem is how to draw the line?" - what is the problem with that? When paintEvent() is called you draw the line.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #23

                      @jsulm said:

                      "Now the problem is how to draw the line?" - what is the problem with that? When paintEvent() is called you draw the line.

                      But then it means paintEvent() is called directly in resizeEvent()?
                      Is something like the code below possible?

                      void MainWindow::resizeEvent(QResizeEvent *event)
                      {
                      
                          //scaled window size
                          scaledWidth = double(event->size().width())/360.0;
                          scaledHeight = double(event->size().height())/180.0;
                      
                          //QString inFile = ":/input.txt";
                          //QString outFile = "output.txt";
                      
                          //set label window size
                          ui->label->setGeometry(0, 0, 360*scaledWidth, 180*scaledHeight);
                      
                          //set draworbit window size
                          //path->drawPath(inFile, outFile, scaledWidth, scaledHeight);
                          path->calculatedXY(someVector, scaledWidth, scaledHeight);
                          path->paintEvent();
                          path->setGeometry(0, 0, 360*scaledWidth, 180*scaledHeight);
                      }
                      
                      1 Reply Last reply
                      0
                      • jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #24

                        No, paintEvent() is called by Qt whenever a repaint is needed.
                        For example it is called after resizing a widget (as stated in documentation).

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        ? 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          No, paintEvent() is called by Qt whenever a repaint is needed.
                          For example it is called after resizing a widget (as stated in documentation).

                          ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #25

                          @jsulm ok. sorry for a dumb question. I have tried it before but it didn't work so I wasn't sure if I understand how it works correctly.

                          So I tried calling the calculatedXY() directly in resizeEvent(), the line is drawn but not scaled when window is maximized. It is scaled only when I call the whole drawPath().

                          However, even calling directly calculatedXY() in resizeEvent(), the lag persists. Still appx 4 secs delay....

                          I have tried changing the size of the background img, even removed it, but still get the same result. I have no idea what could be a reason....

                          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