[SOLVED DIFFERENTLY] Overwrite the CSS style of a web page element



  • Hi,

    With Qt 4.8, I used to rely on the "@import" statement to import a CSS file into another, but for some (very annoying) reason it doesn't work anymore in Qt 5 (see "http://qt-project.org/forums/viewthread/23746/":http://qt-project.org/forums/viewthread/23746/). So, I thought I would do things differently, but now I am facing another unrelated issue.

    Basically, my application's help is made of a series of HTML files which are styled using CSS. Those HTML files are used both on my application's website and within my application. In some HTML files, I have some code which I have styled in a certain way, the idea being not to show that code on my application's website while showing it within my application.

    For this, I have a very simple CSS rule [1]:

    @span.myapp {
    display: none;
    }@

    So, this means that by default (i.e. on my application's website), the code is not shown. Now, in my application, I want to see the code, so I thought I would use something like:

    @myWebView->page()->settings()->setUserStyleSheetUrl(QUrl::fromLocalFile(myLocalCssFile));@

    myLocalCssFile points to a file which has the following contents [2]:

    @span.myapp {
    display: inline;
    }@

    So, yes, some very simple code to show the code within my application. Yet, it doesn't work!

    Interestingly (so to speak!), if I completely remove [1] and replace [2] with:

    @span.myapp {
    color: rgb(255, 0, 0);
    }@

    Then, the code will be shown in all cases, except that within my application it will be in red.

    So... it would seem that for (yet) some (more very annoying) reason, something is broken in Qt 5... or have I done something wrong. Hopefully, it's the latter...

    Anyway, anyone any idea?

    Cheers, Alan.



  • FWIW, I never managed to fix the above issue. However, I was originally using CSS imports in the Qt 4 version of my project. It's just that when porting it to Qt 5, the syntax changed and I couldn't find it, so I thought at the time I would try to get the same result using a different approach (which resulted in the issue above). Then, I managed to guess the correct syntax for CSS imports in Qt 5 ("http://qt-project.org/forums/viewthread/23746/":http://qt-project.org/forums/viewthread/23746/), so the above issue is not relevant to me anymore...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.