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. [Solved] Advice needed: Reload page on "F5"
Forum Updated to NodeBB v4.3 + New Features

[Solved] Advice needed: Reload page on "F5"

Scheduled Pinned Locked Moved Qt WebKit
12 Posts 5 Posters 7.2k 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.
  • M Offline
    M Offline
    miroslav
    wrote on last edited by
    #2

    If you are reimplementing the web view, you can handle keyPressEvents, and catch F5. If not, you could use an event filter.

    Mirko Boehm | mirko@kde.org | KDE e.V.
    FSFE Fellow
    Qt Certified Specialist

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #3

      I would try to add a [[doc:QAction]] together with a shortcut to the webview. You don't need to subclass for this approach, just set the webview as the parent of the action.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #4

        @QKeySequence keys_refresh(Qt::Key_F5);
        this->action_refresh = new QAction(this->view);
        this->action_refresh->setShortcut(keys_refresh);
        connect(this->action_refresh, SIGNAL(triggered()),this->view,SLOT(reload()));
        @

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #5

          Better would be to use

          @
          QKeySequence keys_refresh(QKeySequence::Refresh);
          @

          This way you get the key sequence the user expects on his platform.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #6

            Topic subject is : Reload page on “F5” ;)

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on last edited by
              #7

              But I think QKeySequence::Refresh & Qt::Key_F5 are synonyms, at least for X11 & WIN platforms. isn't they?

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #8

                Yes, they are. And if you're only on platforms that use F5, it makes no difference for you. But why use something hardcoded, when there's a general solution.

                And if someone is not aware of the standard key sequences, how should that be reflected in the topic title?

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  eikeR
                  wrote on last edited by
                  #9

                  Thanks so far!
                  Unfortunately it's not working. Can you see what's wrong? For ease of use, I put the code in the main.cpp, which I will not do in the end, but right now it makes it easier to trace my mistake...

                  @
                  //extract from main.cpp:
                  QApplication app(argc, argv);
                  QWebView window;
                  //[ ... some connects on window->page() and window->page()->mainFrame() ...]
                  QKeySequence keys_refresh(QKeySequence::Refresh); //or (Qt::Key_F5), doesn't matter
                  QAction* actionReload = new QAction(&window);
                  actionReload->setShortcut(keys_refresh);
                  QObject::connect(actionReload, SIGNAL(triggered()), &window, SLOT(reload()));

                  window.load(QUrl("file:///C:/start.html"));
                  window.show();
                  app.exec();
                  @

                  If I make right-click -> reload on my html page, the page gets reloaded, but not if I press F5.
                  [Edit: Even if I make s subclass and override the reload() slot, I see that the slot is not called. So either the action is not triggered, or the signal-slot connection is wrong]

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    AcerExtensa
                    wrote on last edited by
                    #10

                    you have forget to add action to WebView:

                    @window.addAction(actionReload);@

                    God is Real unless explicitly declared as Integer.

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      eikeR
                      wrote on last edited by
                      #11

                      [quote author="AcerExtensa" date="1335439172"]you have forget to add action to WebView:

                      @window.addAction(actionReload);@[/quote]

                      Great, I was just wondering what kind of black magic binds the action to the window :-) Okay, that's it. Thank you all (also thanks for the first answer, maybe I will also have to use the keyPressEvent() override for some other stuff, but for the reload it's easier to use QActions.)

                      1 Reply Last reply
                      0
                      • sierdzioS Offline
                        sierdzioS Offline
                        sierdzio
                        Moderators
                        wrote on last edited by
                        #12

                        If nothing changed during my lengthy absence from this forum, you should now change the topic's title/ subject to include "[Solved]" at the beginning. I've also tagged it for you.

                        (Z(:^

                        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