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. Qt button clicked slot is omniscient?
Qt 6.11 is out! See what's new in the release blog

Qt button clicked slot is omniscient?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.9k 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.
  • B Offline
    B Offline
    Brazzoni
    wrote on last edited by
    #1

    So this is strange, when the code below is implemented, upon pushing the button, it will sleep first and then set the graphics view scene to the newScene. I made the hiddenSleepFunction when this was happening with Sleep() instead of the hidden function, however the clicked function still elects to sleep first and then execute the rest of the code? what?

    void CanvasTest::on_pushButton_2_clicked()
    {
        QGraphicsScene* scene = ui->PixMapView->scene();
        QGraphicsScene* newScene = new QGraphicsScene(0,0,200,300);
        ui->PixMapView->setScene(newScene);
        hiddenSleepFunction();
       // ui->PixMapView->setScene(scene);
    }
    
    void hiddenSleepFunction()
    {
        Sleep(4000);
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Repainting is not an immediate action. Basically you are blocking the event loop so refreshing the GUI wit your new scene will only happen after the loop has run which will be after your Sleep call.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply
      3
      • B Offline
        B Offline
        Brazzoni
        wrote on last edited by
        #3

        huh well that's interesting, thanks for the reply. Is there programming terminology for the fact that repainting isn't an immediate action? I just don't understand why this is so.

        jsulmJ 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Repainting is not an immediate action. Basically you are blocking the event loop so refreshing the GUI wit your new scene will only happen after the loop has run which will be after your Sleep call.

          B Offline
          B Offline
          Brazzoni
          wrote on last edited by
          #4

          @SGaist Also one other question if I may. I'm also trying to scale the pixmap I have in my graphics view widget using ui->graphicsviewObject->scale(xfactor,yfactor) however all this seems to accomplish is breaking my pixmaps and displaying a blank white page. Does this relate to the fact that repainting is not an immediate action (it never displays the pixmap though for clarity).

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            It's explained in the QWidget::paintEvent method documentation.

            You are scaling the view not the pixmap itself.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • B Brazzoni

              huh well that's interesting, thanks for the reply. Is there programming terminology for the fact that repainting isn't an immediate action? I just don't understand why this is so.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #6

              @Brazzoni said in Qt button clicked slot is omniscient?:

              I just don't understand why this is so

              Because as @SGaist said you're blocking the event loop. If event loop is blocked events (including paint events) are not handled.
              One of most important rules using asynchronous frameworks like Qt is: do not block the event loop.

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

              1 Reply Last reply
              2

              • Login

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