Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. File dialog from <input type="file"> causes main window to lose focus
Forum Updated to NodeBB v4.3 + New Features

File dialog from <input type="file"> causes main window to lose focus

Scheduled Pinned Locked Moved Qt WebKit
6 Posts 2 Posters 2.9k 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.
  • S Offline
    S Offline
    ShiraNai7
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brcontainer
      wrote on last edited by
      #2

      You set the "this" in your Dialog window?

      Could provide a working example code of your problem?

      QT project: https://github.com/brcontainer/qt-helper

      1 Reply Last reply
      0
      • S Offline
        S Offline
        ShiraNai7
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          brcontainer
          wrote on last edited by
          #4

          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/

          QT project: https://github.com/brcontainer/qt-helper

          1 Reply Last reply
          0
          • B Offline
            B Offline
            brcontainer
            wrote on last edited by
            #5

            ShiraNai7 I hope you read this. :)

            I managed to solve the problem like this:

            Add in html5applicationviewer.cpp:

            @class customWebPage : public QWebPage {
            Q_OBJECT

            private:
            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()));
            }@

            QT project: https://github.com/brcontainer/qt-helper

            1 Reply Last reply
            0
            • S Offline
              S Offline
              ShiraNai7
              wrote on last edited by
              #6

              Thanks! I will try that :)

              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