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 load multiple css files in QWebView
Forum Updated to NodeBB v4.3 + New Features

How to load multiple css files in QWebView

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.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.
  • S Offline
    S Offline
    Sidii
    wrote on last edited by
    #1

    Dear All,
    I am able to load the single CSS file using the below code:

    view->settings()->setUserStyleSheetUrl( QUrl::fromLocalFile("D:/mycss/mycss1.css") );
    

    But i don't know how to do the same for multiple CSS files like css1.css, css2.css, css3.css
    Only the latest included css file is effective and rest css files are ignored.

    Kindly help!!

    Thanks
    Sid

    1 Reply Last reply
    0
    • veryqtpersonV Offline
      veryqtpersonV Offline
      veryqtperson
      wrote on last edited by veryqtperson
      #2

      Do all these CSSes (css1.css, css2.css...) style the same elements/selectors? If yes, then it's how CSS works. Only the latest one will have an effect (will overlap all previous).

      Anyway, you can (either/or):

      1. Merge all your CSS into one file;
      2. Create a "general" one and use @import url("css1.css"); for every CSS you want in it;
      3. Add them from HTML with <link rel="stylesheet" type="text/css" href="path2css.css"/>? I don't know if it's possible within QWebView.
      S 1 Reply Last reply
      0
      • veryqtpersonV veryqtperson

        Do all these CSSes (css1.css, css2.css...) style the same elements/selectors? If yes, then it's how CSS works. Only the latest one will have an effect (will overlap all previous).

        Anyway, you can (either/or):

        1. Merge all your CSS into one file;
        2. Create a "general" one and use @import url("css1.css"); for every CSS you want in it;
        3. Add them from HTML with <link rel="stylesheet" type="text/css" href="path2css.css"/>? I don't know if it's possible within QWebView.
        S Offline
        S Offline
        Sidii
        wrote on last edited by
        #3

        @veryqtperson Thanks for your reply.
        I tried the same thing. I created one common CSS file and added import for every CSS i need. I am able to load the CSS in browser but somehow its not reflecting in QWebView. Any idea how to debug further?

        Thanks in advance !!

        -Sid

        1 Reply Last reply
        0
        • veryqtpersonV Offline
          veryqtpersonV Offline
          veryqtperson
          wrote on last edited by
          #4

          Unfortunately, that's where my expertise ends, as I haven't done anything with QWebView yet :)

          S 1 Reply Last reply
          0
          • veryqtpersonV veryqtperson

            Unfortunately, that's where my expertise ends, as I haven't done anything with QWebView yet :)

            S Offline
            S Offline
            Sidii
            wrote on last edited by
            #5

            @veryqtperson No issues. Thanks for your time :)

            raven-worxR 1 Reply Last reply
            0
            • S Sidii

              @veryqtperson No issues. Thanks for your time :)

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Sidii
              a possibility would be to read all your CSS files and concatenate them into a string. Then pass the base64 encoded string to the webview.

              webview->settings()->setUserStyleSheetUrl( QUrl( QString("data:text/css;charset=utf-8;base64,") % QByteArray( CSS-string ).toBase64() ) );
              

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              S 1 Reply Last reply
              2
              • raven-worxR raven-worx

                @Sidii
                a possibility would be to read all your CSS files and concatenate them into a string. Then pass the base64 encoded string to the webview.

                webview->settings()->setUserStyleSheetUrl( QUrl( QString("data:text/css;charset=utf-8;base64,") % QByteArray( CSS-string ).toBase64() ) );
                
                S Offline
                S Offline
                Sidii
                wrote on last edited by
                #7

                @raven-worx Thanks !!

                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