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. Conflict between showing QDialog and updating QGLWidget
Qt 6.11 is out! See what's new in the release blog

Conflict between showing QDialog and updating QGLWidget

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 2.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi,

    I've a qt project that was implemented using qt3 and then ported to qt4 using qt3support.

    Before porting I was showing a dialog then updating in a QGLWidget, this was working with no error

    here is a sample of the code

    @
    QDialog* dlg = new QDialog();
    dlg->show();
    dlg->raise();
    dlg->activateWindow();

    // code for updating QGLWidget by updating the scene graph matrix
    ....
    @

    after porting this code produces an errors like that "QPainter::setPen: Painter not active" which means I'm using
    painter outside paint event, however I don't.

    after some investigation I guessed that I need to wait until the dialog is fully painted then go update the QGLWidget.
    However I didn't find any signals in QWidget or QDialog that tells me that the dialog has finished painting.

    To test my guessing I have placed a message box after showing the dialog and before accessing the QGLWindget
    and this worked successfully but for sure this isn't appropriate solution.

    @
    QDialog* dlg = new QDialog();
    dlg->show();
    dlg->raise();
    dlg->activateWindow();
    QMessage::critical(NULL , "test" , "Wait till the dialog finishes showing all items");

    // code for updating QGLWidget by updating the scene graph matrix
    ....
    @

    So is there any way to avoid this error or any way to tell me that the dialog finished painting?

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

      Hi,

      There's something not clear here. Where/when do you call that dialog ?

      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
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Hi,

        The dialog is shown after pressing a button in my application,
        This button functionality is to zoom in the QGLWidget and show the QDialog to use it in some functionality later.

        Hint: the QGLWidget is initialized and already showing a view, after pressing the button we just zoom in to certain area.

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

          Where are you creating that dialog ? From the QGLWidget or from somewhere else ?

          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
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            From somewhere else.

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

              What version of Qt are you using ? On what OS ?

              Can you replicate that with a minimal code sample ?

              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
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                QT version : 4.8.3 with qt3 support
                OS : RHEL 5.7

                What is not clear in the sample code I provided before?

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

                  You sample code just shows that you are creating a dialog, showing it and also show a QMessageBox.

                  It doesn't tell how you do it with your application nor does it allow to test your use case to reproduce your problem

                  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
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    Here is a sample from all the code I think you may need to understand the problem

                    my dialog code , dialog is inherited from QWidget

                    @MyDialogClass::MyDialogClass(QWidget* parent, const char* name, Qt::WindowFlags fl)
                    : QWidget(parent, name, fl)
                    {
                    setupUi(this);
                    init();
                    }

                    MyDialogClass::setupUi(Qwidget* myDialog)
                    {
                    if (myDialog->objectName().isEmpty())
                    myDialog->setObjectName(QString::fromUtf8("untitled"));
                    myDialog->resize(379, 161);
                    vboxLayout = new QVBoxLayout(myDialog);
                    vboxLayout->setSpacing(6);
                    vboxLayout->setContentsMargins(11, 11, 11, 11);
                    vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
                    hboxLayout = new QHBoxLayout();
                    hboxLayout->setSpacing(6);
                    hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
                    textLabel1_2 = new QLabel(myDialog);
                    textLabel1_2->setObjectName(QString::fromUtf8("textLabel1_2"));
                    textLabel1_2->setWordWrap(false);

                        hboxLayout->addWidget(textLabel1_2);
                    
                        lineEdit = new QLineEdit(myDialog);
                        lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
                        QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(3), static_cast<QSizePolicy::Policy>(0));
                        sizePolicy.setHorizontalStretch(0);
                        sizePolicy.setVerticalStretch(0);
                        sizePolicy.setHeightForWidth(m_summaryLE->sizePolicy().hasHeightForWidth());
                        lineEdit->setSizePolicy(sizePolicy);
                        lineEdit->setReadOnly(true);
                    
                        hboxLayout->addWidget(lineEdit);
                    
                        toolButton = new QToolButton(myDialog);
                        tooButton->setObjectName(QString::fromUtf8("first button"));
                        QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(5));
                        sizePolicy1.setHorizontalStretch(0);
                        sizePolicy1.setVerticalStretch(0);
                        sizePolicy1.setHeightForWidth(tooButton->sizePolicy().hasHeightForWidth());
                        tooButton->setSizePolicy(sizePolicy1);
                    
                        hboxLayout->addWidget(tooButton);
                    
                    
                        vboxLayout->addLayout(hboxLayout);
                    

                    ....

                        QMetaObject::connectSlotsByName(myDialog);
                    

                    }

                    MyDialogClass::init()
                    {
                    //connect signals of buttons
                    connect(firstButton, SIGNAL(clicked()),this, SIGNAL(FirstButtonAction()));
                    ....
                    // End of connecting signals.
                    }@

                    the myGLCanvas code, it is inherited from QGLWidget

                    @myGLCanvas::setProjectionMatrix()
                    {
                    QGLWidget::makeCurrent();
                    glMatrixMode(GL_PROJECTION);
                    glLoadIdentity();
                    glOrtho(clipL, clipR, clipB, clipT, -1, 1);
                    glMatrixMode(GL_MODELVIEW);
                    glLoadIdentity();
                    glTranslatef(0., 0., 0.0);
                    }

                    myGLCanvas::zoom(point p1, point p2)
                    {
                    // setting clipR , clipL , clipT , clipB variable from points p1, p2

                    setProjectionMatrix();
                    // make paintGl update the scene
                    update = true;
                    }

                    myGlCanvas::paintGl()
                    {
                    glLoadIdentity();
                    ....
                    myGLWindow *de = viewer->getEditorWindow();
                    if (update)
                    {
                    FormState menuBarState = de->getMenuBarState();
                    if (formState == Closing || formState == ClosingRedraw ||
                    menuBarState == Closing)
                    {
                    if (formState == Closing || formState == ClosingRedraw)
                    {
                    formState = Hidden;
                    }
                    if (menuBarState == Closing)
                    {
                    de->setMenuBarState(Hidden);
                    }
                    update();
                    }
                    else
                    {
                    de->setWaitCursor("Drawing ...");

                          update = false;
                    
                          emit canvasAboutRedraw();
                          drawCanvasArea(drawArea);
                          emit canvasRedrawn();
                          de->restoreCursor(false);
                        }
                    }
                    ....
                    

                    }
                    @

                    the code producing the error, it is slot of clicking a button from the main window of my application

                    @void zoomAndShowDialogBtnClickedSlot()
                    {
                    std::vector<point> zoomPoints = getZoomPoints();
                    MyDialogClass* myDialog = new MyDialogClass();

                    QStringList typesQ;
                    for(int i=0; i<items.size(); ++i)
                    {
                    typesQ.append(items[i]);
                    }
                    myDialog->setTypeList(typesQ);
                    if(typesQ.size() > 0)
                    {
                    myDialog->setType(typesQ[0]);
                    }

                    myDialog->setTitleName("title ");

                    myDialog->show();
                    myDialog->raise();
                    myDialog->activateWindow();

                    // zoom in the QGLWidget
                    // myGLCanvas is already initiated and viewing contents, we just need to zoom in it
                    myGLCanvas->zoom(points.at(0),points.at(1));

                    }@

                    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