Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set QWebView content from QHelpEngineCore to enable CSS links?
Forum Updated to NodeBB v4.3 + New Features

How to set QWebView content from QHelpEngineCore to enable CSS links?

Scheduled Pinned Locked Moved General and Desktop
28 Posts 3 Posters 15.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.
  • M Offline
    M Offline
    mirswith
    wrote on last edited by
    #5

    I tried that, unfortunately QWebView does not (as far as I can tell) recognize qthelp:// url schemes.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #6

      Sry I'm not familiar with the mechanics or use of the HelpEngine. How exactly do the returned Url's look like? In QHelpEngineCore's documentation it says:
      QUrl QHelpEngineCore findFile( const QUrl &url) const
      Returns an invalid URL if the file url cannot be found. If the file exists, either the same url is returned or a different url if the file is located in a different namespace which is merged via a common virtual folder.

      don't know if that might be of any help.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mirswith
        wrote on last edited by
        #7

        I can load url's no problem. The problem is the urls within the page itself, QWebView does not recognize QtHelp url's and there appears to be no way to intercept the urls and load the data yourself to pass on to the web view as you can with QTextBrowser.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on last edited by
          #8

          If you could read the content of the css files you could then create a new file at any location insert the css content and set your own Url for the WebView. Bit of an overkill but I can't think of anything else. Sorry.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mirswith
            wrote on last edited by
            #9

            Unfortunately that is what I ended up doing, while it is working ok for now since I am only looking for a single css file; this approach will limit me when it comes to inserting other things, such as Images. :(

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KA51O
              wrote on last edited by
              #10

              How does QHelpEngineCore store the file connected to a Url internally? Are the files stored in a Resource file, or are they actually stored at a specific location like maybe "..\QHelpEngineCoreInstallationDir\files\someFile.css" so you could map the QUrl provided by QHelpEngineCore to a representation you can use for your WebView.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mirswith
                wrote on last edited by
                #11

                They are stored in a sqlite database.

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  Woody
                  wrote on last edited by
                  #12

                  Can i bring this topic back to life?

                  I thought that with this code it would work:
                  @QByteArray helpData = m_helpEngine->fileData(url);
                  QByteArray styles = m_helpEngine->fileData(QUrl("qthelp://com.mynamespace/doc/styles/style.css"));
                  if(!helpData.isEmpty())
                  {
                  ui->webView->setStyleSheet(styles);
                  ui->webView->setHtml(helpData);
                  }@

                  Even when using css inline in the HTML-file isn't working.
                  You would think the code above should give me a decent webpage with css.

                  But no, even my second option isn't showing me anything.

                  File not found. Nobody leave the room!

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    KA51O
                    wrote on last edited by
                    #13

                    the "setHtml(..)":https://qt-project.org/doc/qt-4.8/qwebview.html#setHtml function needs the Html as QString and to be able to load all the resources linked in the Html (e.g. the style sheet) you must provide the BaseUrl. If your Html has no stylesheet resource defined (<link rel="stylesheet" type="text/css" href="myStyleSheet.css">) you may need to add that to make it work.
                    Also the "setStyleSheet(..)":https://qt-project.org/doc/qt-4.8/qwidget.html#styleSheet-prop function is inherited from QWidget and is used to set the style for the widget (your WebView) and not the Html content of the WebView.

                    Its just a shot in the dark and I haven't tried it myself, but maybe this will work:
                    @
                    QString myHtmlContent = QString( m_helpEngine->fileData(url) );
                    QUrl myBaseUrl = QUrl("qthelp://com.mynamespace/doc/styles")
                    if(!myHtmlContent.isEmpty())
                    {
                    ui->webView->setHtml(myHtmlContent, myBaseUrl);
                    }
                    @

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      Woody
                      wrote on last edited by
                      #14

                      It is showing me more (e.g. an icon where the image has to be) still no styles though.

                      This is what is in my head-tag in the html-file:
                      <link href="../style/styles.css" rel="stylesheet" type="text/css">

                      my map-structure like this:
                      doc

                      • images
                      • style
                        styles.css
                      • ...

                      so the baseUrl should be right with:
                      @QUrl("qthelp://com.mynamespace/doc");@

                      But doing nothing, are there maybe things QWebview can't display? Cause I even got problems loading a simple online webpage :s

                      File not found. Nobody leave the room!

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        KA51O
                        wrote on last edited by
                        #15

                        If you have problems displaying images, this might result from missing plugins. You need to have the following structure in the directory your running your code from: plugins\imageformats\qjpeg4.dll ... and all the other plugins you need for the different image datatypes. You can find the plugins folder in your Qt folder.

                        I really don't know if the combination of qtHelp Urls and Html can work. Maybe you can try to find out more by using the "WebInspector":http://qt-project.org/doc/qt-4.8/qwebinspector.html for your WebPage.

                        1 Reply Last reply
                        0
                        • W Offline
                          W Offline
                          Woody
                          wrote on last edited by
                          #16

                          I don't think I'm understanding you well.

                          I know where to find the plugins (and they are there), but do I need to put the dlls in my debug/release map or in my main projects folder? e.g. myapplication\debug\plugins\imageformats... or myapplication\plugins\imageformats...

                          It's a pitty you can't debug assistant, cause that is almost what i need. What it displays.
                          But it doens't seem to work in my QWebview.

                          File not found. Nobody leave the room!

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            KA51O
                            wrote on last edited by
                            #17

                            The idea with the plugins was just a guess. I think enabling the "QWebInspector":http://qt-project.org/doc/qt-4.8/qwebinspector.html is the first thing you should try.

                            1 Reply Last reply
                            0
                            • W Offline
                              W Offline
                              Woody
                              wrote on last edited by
                              #18

                              And how can I use that? I never worked with QWebview (apart from this subject), let alone that I worked with QWebInspector.

                              I've tried to put create a QWebPage like:
                              @QWebPage *page = ui->webView->page();@
                              and a QWebinspector like so:
                              @QWebInspector *inspector = new QWebInspector;@

                              when i try to set my page, nothing happens, my QWebPage is empty...

                              File not found. Nobody leave the room!

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                KA51O
                                wrote on last edited by
                                #19

                                I haven't used the WebInspector myself but the documentation of it is pretty much selfexplanatory. After you have set the Html content for your WebView, you just need to get the WebPage pointer from the WebView, create the WebInspector and set the page for the WebInspector.
                                @
                                ui->yourWebView->setHtml(yourContent, yourBaseUrl);
                                QWebInspector *inspector = new QWebInspector(ui->yourWebView);
                                inspector->setPage(ui->yourWebView->page());
                                inspector->setVisible();
                                @
                                If this is not working, maybe you also need to set some settings to make it work (QWebSettings::DeveloperExtrasEnabled). Have a look at "QWebSettings":https://qt-project.org/doc/qt-4.8/qwebsettings.html this class also has a function called setUserStyleSheetUrl(..).

                                1 Reply Last reply
                                0
                                • W Offline
                                  W Offline
                                  Woody
                                  wrote on last edited by
                                  #20

                                  Sorry if I have to bother you again:s
                                  But nothing is happening. Even not showing the inspector anymore.

                                  And this is what i'm trying to do:

                                  @QString myHtmlContent = QString(m_helpEngine->fileData(url));
                                  QUrl myBaseUrl = QUrl("qthelp://com.mynamespace/doc");
                                  if(!myHtmlContent.isEmpty())
                                  {
                                  // ui->webView->setContent(helpData, QString(), myBaseUrl);
                                  ui->webView->setHtml(myHtmlContent, myBaseUrl);
                                  }

                                  //QWebPage *page = ;
                                  ui->webView->page()->settings()->DeveloperExtrasEnabled;
                                  QWebInspector *inspector = new QWebInspector(ui->webView);
                                  inspector->setPage(ui->webView->page());
                                  inspector->setVisible(true);@

                                  [EDIT] It works: @ui->webView->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);@

                                  File not found. Nobody leave the room!

                                  1 Reply Last reply
                                  0
                                  • K Offline
                                    K Offline
                                    KA51O
                                    wrote on last edited by
                                    #21

                                    Do the style sheets and images also work now ?

                                    1 Reply Last reply
                                    0
                                    • W Offline
                                      W Offline
                                      Woody
                                      wrote on last edited by
                                      #22

                                      Ok now that I got that, nothing seems to be loaded. No images, no stylesheets...

                                      File not found. Nobody leave the room!

                                      1 Reply Last reply
                                      0
                                      • W Offline
                                        W Offline
                                        Woody
                                        wrote on last edited by
                                        #23

                                        !http://wouterverbruggen.be/img/outcome.jpg(outcome)!

                                        As you can see, no content is loaded (i think)

                                        File not found. Nobody leave the room!

                                        1 Reply Last reply
                                        0
                                        • K Offline
                                          K Offline
                                          KA51O
                                          wrote on last edited by
                                          #24

                                          Maybe you can first test with a local Html file ,Css file and image and get that working and then proceed with the qHelp Urls. Just to pinpoint the error source.

                                          Edit: Have you checked the QString holding the Html content?

                                          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