Conflict between showing QDialog and updating QGLWidget
-
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?
-
Hi,
There's something not clear here. Where/when do you call that dialog ?
-
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.
-
Where are you creating that dialog ? From the QGLWidget or from somewhere else ?
-
From somewhere else.
-
What version of Qt are you using ? On what OS ?
Can you replicate that with a minimal code sample ?
-
QT version : 4.8.3 with qt3 support
OS : RHEL 5.7What is not clear in the sample code I provided before?
-
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
-
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, p2setProjectionMatrix();
// 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));}@