Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Not painting

    General and Desktop
    2
    8
    87
    Loading More Posts
    • 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.
    • Perdrix
      Perdrix last edited by Perdrix

      I have a widget (SelectRect) that (I am fairly sure) is on top of another widget that displays an image

      The top widget uses:

      setAttribute(Qt::WA_TransparentForMouseEvents);
      setAttribute(Qt::WA_NoSystemBackground);
      setAttribute(Qt::WA_WState_ExplicitShowHide);
      

      and the Image display widget drives the mouseEvent handlers of the top level widget.

      Both of those widgets are displayed in the central area of a QMainWindow.

      There's also a docked dock widget.

      When I first load an image and click on it the mousePressEvent of the top window is driven which in turn calls update() to drive paintEvent(). I have qDebug() code in the paintEvent code so I know the rectangles I want are being drawn.

      Unfortunately, when this code is run the stuff drawn in paintEvent is not visible. If I then undock the dock widget, or just move the bar to change the size of the dock widget, the paintEvent stuff suddenly appears and I have no further problems...

      First pass before sizing the dock widget - when I left mouse click in the image I get this:
      4af1465a-c436-4fb4-9dbe-090863d6f9db-image.png

      After resizing the dock widget when I left click in the image I get this - which is what I expected to see above:

      24772013-a70e-4a66-b328-3943fe29b59d-image.png

      I am baffled!

      The code for selectrect.cpp and .h is here:

      https://www.dropbox.com/s/muw9p27coiuwcxp/selectrect.zip?dl=1

      Thanks in advance
      David

      Axel Spoerl 1 Reply Last reply Reply Quote 0
      • Perdrix
        Perdrix @Axel Spoerl last edited by Perdrix

        @Axel-Spoerl Found it!! (At least I think so)

        I needed to change SelectRect::rectButtonPressed() so that it ended with:

                show();
                raise();
                activateWindow();
           }
        
        1 Reply Last reply Reply Quote 1
        • Axel Spoerl
          Axel Spoerl @Perdrix last edited by Axel Spoerl

          Hi David,

          There's also a docked dock widget.
          When I first load an image and click on it the mousePressEvent of the top window is driven which in turn calls update() to drive paintEvent(). I have qDebug() code in the paintEvent code so I know the rectangles I want are being drawn.

          Just to be sure:
          From the window handle, it looks as if "Registering and Stacking" on the left is the dock widget.
          The widget on the right is where the rectangles are being drawn, but not shown (I'll call it Sky-Widget)
          When you undock the dock widget or resize the main window, the rectangles suddenly show up on the Sky-Widget.

          stuff drawn in paintEvent is not visible

          I have a widget (SelectRect) that (I am fairly sure) is on top of another widget that displays an image

          I can't download anything from dropbox, so I don't know the code of SelectRect. But from the name, I would guess that a new SelectRect is instantiated each time the user draws a rectangle.
          So here's a a poke in the dark:

          • The initial Z-order of Sky-Widget and SelectRect doesn't reflect what should be shown. The rectangles are in the background or even hidden (qDebug() << __FUNCTION__ << isVisible();at the end of paintEventwill tell).
          • There is a code path somewhere in the application source, that sets the Z-order right. That code path is not entered after the rectangles have been drawn.
          • The Z-order code path is, however, entered when the main window consumes an updateEvent: That's the case when it's being resized or the dock widget is undocked.
          • Once the Z-order is correct, there are no more problems (Z-orders do not change automagically...).

          => somewhere in the code QWidget::show()or QWidget::raise() is probably called on SelectRect.
          Throwing a few qDebugs into the neighborhood may bring some more insight.

          Cheers
          Axel

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply Reply Quote 2
          • Perdrix
            Perdrix last edited by

            @Axel-Spoerl There are two dock widgets - the one on the left and the list of images at the bottom.

            b2cfdd3e-a38f-4147-ba0a-3e50685a452c-image.png

            SelectRect is instantiated at the same time as the ImageView control (which displays the picture) When you click on an image in the list at the bottom it is loaded into the ImageView instance. When that completes the following code is run (in the case of interest rectAction->isChecked() will be true).

            if (pToolBar->rectAction->isChecked())
            {
            	editStarsPtr->rectButtonPressed();
            	selectRectPtr->rectButtonPressed();
            }
            
            void EditStars::rectButtonPressed()
            {
            	//
            	// No longer interested in signals from the imageView object
            	//
            	imageView->disconnect(this, nullptr);
            	imageView->clearOverlay();
            	hide();
            }
            
            void SelectRect::rectButtonPressed()
            {
                qDebug() << __FUNCTION__;
            
                connect(imageView, SIGNAL(Image_mousePressEvent(QMouseEvent*)), this, SLOT(mousePressEvent(QMouseEvent*)));
                connect(imageView, SIGNAL(Image_mouseMoveEvent(QMouseEvent*)), this, SLOT(mouseMoveEvent(QMouseEvent*)));
                connect(imageView, SIGNAL(Image_mouseReleaseEvent(QMouseEvent*)), this, SLOT(mouseReleaseEvent(QMouseEvent*)));
                connect(imageView, SIGNAL(Image_resizeEvent(QResizeEvent*)), this, SLOT(resizeMe(QResizeEvent*)));
                raise();
                show();
                update();
            
            }
            

            I plastered the code with

            qDebug() << __FUNCTION__ << " visible " << isVisible();
            

            and got lots of output like:

            DSS::SelectRect::mousePressEvent  visible  true
            LMB pressed
            DSS::SelectRect::modeFromPosition  visible  true
            Selection mode  1
            DSS::SelectRect::paintEvent  visible  true
            

            Can you pull files from github? If so you can look at the the source of selectrect.cpp here:

            https://github.com/deepskystacker/DSS/blob/release/DeepSkyStacker/selectrect.cpp

            Thanks, David

            Axel Spoerl 1 Reply Last reply Reply Quote 0
            • Axel Spoerl
              Axel Spoerl @Perdrix last edited by

              @Perdrix
              Hi David,
              had a brief look at the class, but there's nothing that screams to me right away.
              It would require some debugging of the entire application, to isolate the issue.
              But since it's quite large and not a CMake project that I could just open with Qt Creator, I fear that this one goes beyond the scope of this forum.
              Maybe someone else spots what I seem to miss.
              Cheers
              Axel

              Software Engineer
              The Qt Company, Oslo

              Perdrix 1 Reply Last reply Reply Quote 0
              • Perdrix
                Perdrix @Axel Spoerl last edited by Perdrix

                @Axel-Spoerl The plot thickens - I now have reports of only 2 or 3 sides of the drawn rectangle(s) being visible.

                So I am beginning to smell a video driver issue. What do you think.

                I have an Intel P360 and nVidia RTX5000. I'm not sure which adapter is in charge here.

                Axel Spoerl 1 Reply Last reply Reply Quote 0
                • Axel Spoerl
                  Axel Spoerl @Perdrix last edited by

                  @Perdrix
                  Hi David,
                  The video driver could be one issue, XCB as well.
                  I have seen weird situations where XCB events were handled in the wrong order.
                  Brgds
                  Axel

                  Software Engineer
                  The Qt Company, Oslo

                  Perdrix 2 Replies Last reply Reply Quote 0
                  • Perdrix
                    Perdrix @Axel Spoerl last edited by

                    @Axel-Spoerl XCB? What's that?

                    1 Reply Last reply Reply Quote 0
                    • Perdrix
                      Perdrix @Axel Spoerl last edited by Perdrix

                      @Axel-Spoerl Found it!! (At least I think so)

                      I needed to change SelectRect::rectButtonPressed() so that it ended with:

                              show();
                              raise();
                              activateWindow();
                         }
                      
                      1 Reply Last reply Reply Quote 1
                      • Topic has been marked as solved  Perdrix Perdrix 
                      • First post
                        Last post