File dialog from <input type="file"> causes main window to lose focus
-
Hello.
I am completely new to C++ and Qt as well, so this may be a dumb question.
I have a simple application based on Html5ApplicationViewer. Everything is fine, but when a file dialog is opened by pressing the "Choose File" of an <input type="file">, the application loses focus (some other window is activated) after the dialog is finished. This happens even in newly created HTML5 Application project. I know this may be caused by/related to the file dialog having no defined parent (?)
Is there a way to fix it without rewriting half of Html5ApplicationViewer?
-
You set the "this" in your Dialog window?
Could provide a working example code of your problem?
-
I am not opening the dialog. Webkit is. It's from an <input type=“file”> on the page.
To create an example - just create new "HTML5 Application" project, put <input type="file"> somewhere in the index.html and run it. And then, when you choose a file, the main window loses focus as I have described.
-
the problem actually occurs in Windows (not tested in others).
There seems to be a bug, but a lack of implementation. Your application requires even a html5application, could not be a QWebView?
If you want to report the bug, see: http://bugreports.qt-project.org/
-
ShiraNai7 I hope you read this. :)
I managed to solve the problem like this:
Add in html5applicationviewer.cpp:
@class customWebPage : public QWebPage {
Q_OBJECTprivate:
QWidget *window;
QString lastDir;public:
void setParentWindow(QWidget *parent = 0);protected:
virtual QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile);
};void customWebPage::setParentWindow(QWidget *parent) {
window = parent;
}QString customWebPage::chooseFile(QWebFrame originatingFrame, const QString &oldFile) {
if(lastDir==""){
lastDir = QDir::currentPath();
}
QString fileName = QFileDialog::getOpenFileName(
window,
"Select...",
lastDir,
tr("All files (.*)")
);
if(fileName!=""){
lastDir = QFileInfo(fileName).absolutePath();
return fileName;
}
return oldFile;
}@In function "Html5ApplicationViewerPrivate::Html5ApplicationViewerPrivate(QWidget *parent)", add "setPage", eg.:
@Html5ApplicationViewerPrivate::Html5ApplicationViewerPrivate(QWidget *parent)
: QGraphicsView(parent)
{
QGraphicsScene *scene = new QGraphicsScene;
setScene(scene);
setFrameShape(QFrame::NoFrame);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);customWebPage *m_webPage = new customWebPage();//customWebPAge m_webPage->setParentWindow(parent);//custom function, set parent window m_webView = new QGraphicsWebView; m_webView->setPage(m_webPage);//setPage in webView m_webView->setAcceptTouchEvents(true); m_webView->setAcceptHoverEvents(false); setAttribute(Qt::WA_AcceptTouchEvents, true); scene->addItem(m_webView); scene->setActiveWindow(m_webView);
#ifdef TOUCH_OPTIMIZED_NAVIGATION
m_controller = new NavigationController(parent, m_webView);
#endif // TOUCH_OPTIMIZED_NAVIGATION
connect(m_webView->page()->mainFrame(),
SIGNAL(javaScriptWindowObjectCleared()), SLOT(addToJavaScript()));
}@ -
Thanks! I will try that :)