QWidget not getting focus after canceling a QDialog...
-
Please bear with me in the following code. The problem occurs with the GLDialog, which is a QDialog with a QGLWidget inside of it. If I cancel the first dialog, no problem. Qt recognizes the calling widget, (the one "this" points), as the active window. But if I cancel the GLDialog, then the calling widget looks like its disabled even though it isn't while its isActive() method returns false. Pressing on the calling widget allows me to move it around and to click on its buttons, etc, but it won't be recognized as active. Anyone seeing this same sort of behavior?
@ // CREATE THE INTERLACE DIALOG TO GET THE USER SETTINGS
LAUFlysEyeInterlaceDialog dialog(800,600);
if (dialog.exec() == QDialog::Accepted){
// KEEP A COPY OF THE INTERLACE PARAMETERS IN CASE WE HAVE MULTIPLE
// DOCUMENTS OPEN AND THE USER WANTS DIFFERENT SETTINGS ON EACH
// MAKE SURE WE HAVE THE CORRECT NUMBER OF IMAGES TO INTERLACE
int numChannels = dialog.imageMatrixHeight() * dialog.imageMatrixWidth();
if (document->count() != numChannels){
QMessageBox::warning(NULL, QString("Interlace Tool"), QString("Interlace settings require %1 images. You have only specified %2.").arg(numChannels).arg(document->count()), QMessageBox::Ok);
} else {
// CREATE A GLWIDGET TO SHOW A SIMULATION OF THE PRINTED IMAGE BEHIND A LENS
QVector3D outputSize(dialog.printWidthInInches(), dialog.printHeightInInches(), 0.01);
LAUFlysEyeGLDialog glDialog(outputSize, document->previews(), dialog.imageMatrixWidth(), dialog.imageMatrixHeight());
if (glDialog.exec() == QDialog::Accepted){
// ASK THE USER FOR A FILE TO SAVE THE RESULTS
QString fileName = QFileDialog::getSaveFileName(0, QString("Save interlaced image to disk (.tif)"), LAUImage::lastUsedDirectory, QString(".tif;*.tiff"));
if (!fileName.isNull()){
LAUImage::lastUsedDirectory = QFileInfo(fileName).absolutePath();
if (!fileName.toLower().endsWith(QString(".tiff"))){
if (!fileName.toLower().endsWith(QString(".tif"))){
fileName = QString("%1.tif").arg(fileName);
}
}// GENERATE A TEMPORARY FILENAME FOR THE INTERLACE MAP QString interlaceMapFilename = LAUFlysEyeDocument::nextAvailableTemporaryFilename(); // CHECK TO SEE IF INTERLACE MAP WAS CREATED WITHOUT ERROR if (dialog.interlaceMask(interlaceMapFilename, false, this)){ document->interlace(fileName, interlaceMapFilename, dialog.getParameters()); } } } } }
@
-
Hi,
Can you also provide which version of Qt you're using on which OS and also how you installed it ?
-
Qt 5.1.1 clang64, Mac OS X 10.9.1
-
First thing you should do is update Qt to 5.2. A lot of work has been done to add support for Mavericks
-
I was unaware that 5.2.0 was available, but I'm afraid it did not help. I still have the issue with 5.2.0. I have an older mac that I will test this on Monday and see if there issue is there as well.
-
If it's also the case, then you should try to create a minimal test program that reproduces the behavior to ensure it's a Qt bug
-
I haven't had a chance to make a test project yet, but I did narrow down the conditions that are causing it. I subclassed QDialog, and manually added an okay button. I then connected the clicked() signal from the button to the subclasses accept slot. I also overrode the closed() method, and if the dialog is closed, this method just calls the accept() method. If the user closes the dialog, then everything is fine. If the user clicks my accept button, then the window closes but the host window never gets focus.
Any thoughts?
-
Then you can make a little test app with just that: one widget, your minimal QDialog and what is needed to show it and trigger that behavior
-
Okay here it is. Run the project. Click on the "Test Button", and it will bring up the QDialog with an QGLWidget. Hit either okay or cancel, and you will see that the QToolButtons in the original widget do not get activated even though they are the only window visible.
Here is my .pro file:
@#-------------------------------------------------
Project created by QtCreator 2014-01-19T17:40:44
#-------------------------------------------------
QT += core gui opengl widgets
TARGET = DialogError
TEMPLATE = appSOURCES += main.cpp
testwidget.cppHEADERS += testwidget.h
@Here is my header file:
@#ifndef TESTWIDGET_H
#define TESTWIDGET_H#include <QDebug>
#include <QWidget>
#include <QDialog>
#include <QGroupBox>
#include <QToolButton>
#include <QGLWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>class TESTDialog : public QDialog
{
Q_OBJECTpublic:
explicit TESTDialog(QWidget *parent = 0);
~TESTDialog();private:
};class TESTWidget : public QWidget
{
Q_OBJECTpublic:
explicit TESTWidget(QWidget *parent = 0);
~TESTWidget();public slots:
void onPushButtonClicked();private:
};#endif // TESTWIDGET_H
@Here is my cpp file:
@#include "testwidget.h"
#include "ui_testwidget.h"TESTWidget::TESTWidget(QWidget *parent) : QWidget(parent)
{
this->setLayout(new QVBoxLayout());
QGroupBox *box = new QGroupBox();
box->setLayout(new QVBoxLayout());
this->layout()->addWidget(box);QWidget *widget = new QWidget(); widget->setLayout(new QHBoxLayout()); QToolButton *button = new QToolButton(); button->setText(QString("Test Button")); connect(button, SIGNAL(clicked()), this, SLOT(onPushButtonClicked())); widget->layout()->addWidget(button); widget->layout()->addWidget(new QToolButton()); widget->layout()->addWidget(new QToolButton()); widget->layout()->addWidget(new QToolButton()); widget->layout()->addWidget(new QToolButton()); box->layout()->addWidget(widget);
}
TESTWidget::~TESTWidget()
{
;
}void TESTWidget::onPushButtonClicked()
{
TESTDialog dialog;
qDebug() << dialog.exec();
}TESTDialog::TESTDialog(QWidget *parent) : QDialog(parent)
{
this->setLayout(new QVBoxLayout());
QGLWidget *widget = new QGLWidget();
widget->setMinimumSize(320,240);
this->layout()->addWidget(widget);QPushButton *button = new QPushButton(QString("Accept")); connect(button, SIGNAL(clicked()), this, SLOT(accept())); this->layout()->addWidget(button); button = new QPushButton(QString("Cancel")); connect(button, SIGNAL(clicked()), this, SLOT(reject())); this->layout()->addWidget(button);
}
TESTDialog::~TESTDialog()
{
;
}
@Look forward to your solution.
-
Given my success at recreating the bug in my test program, I decide to report the issue as a bug; however, I'd be thrilled to find a work around. Perhaps, you can suggest one?
-
I didn't had time to test so I can't right now
Can you post a link to your bug report please ?
-
-
I saw the comment that the code seems to work in 5.2.1, but I don't really want to mess with pre-release code and all the overhead of compiling, etc. Also, you have to look really closely at the tool buttons to notice that they aren't being re-activated dismissing the dialog.
Have you been able to test with 5.2.0 to confirm that you are seeing the issue in that release?
-
You don't need to build it yourself, you can use the pre-built 5.2.1 package
-
You'll have to remind me, how do I get the 5.2.1 binaries? The only binaries I see on the qt-project's download site is 5.2.0.
-
Sorry, I meant the snapshot you can find "here":http://download.qt-project.org/snapshots/qt/5.2/5.2.1/2014-02-02_42/qt-opensource-mac-x64-clang-5.2.1_2014-02-02_17-52-03-42.dmg the version from 02.02.2014
-
Just tried the latest snapshot, but I'm afraid it's still not become active after accepting the dialog. So the bug remains.