Important: Please read the Qt Code of Conduct -

Load video (.mp4) and .css in Qt Help Assistant

  • Hi,
    I'm trying to load some dynamic elements to my application help menu using Qt Help Project File. I have no problem loading the .html files, but other files like .mp4, .png, and .css are not likely taken into account.
    So when I open my application, only a virgin version of my .html files appears (no images, no videos, and no fonts defined in .css, but the content is correct), Idk if I must do anything specific to load files (especially videos) with Qt (because it seems that's a bit tricky with Qt)
    Anyway, my Qt Help Project File looks like this, knowing that the paths are correct, if anyone have an idea please help me out.
    Thanks a lot guys!

    <?xml version="1.0" encoding="UTF-8"?>
    <QtHelpProject version="1.0">
    			<section title="Page" >
    				<section title="Page 1" ref="page1.html"></section>
    				<section title="Page 2" ref="page2.html"></section>
    			<keyword name="Page 1" ref="page1.html"/>
    			<keyword name="Page 2" ref="page1.html"/>

    1. add the Resource file .qrc in QT Project.
      RESOURCES += gui.qrc

    2. add Prefix (/gui) and file (style.css)in gui.qrc with help of Editor.

    gui.qrc file text.

             <qtresource prefix="/gui">
    1. You can use this function. You can call Applystyle function whenever you want to load the .css style.
    void MainWindow::ApplyStyle() {
    #ifndef QT_NO_DEBUG
        QFile f(":/gui/style.css");
    	QString newStyleSheet = f.readAll();
    #ifndef QT_NO_DEBUG
    		QRegExp imageSource("(:/GUI)");
    		QString localSource(".");
    		int offset = 0;
    		while (-1 != (offset = imageSource.indexIn(newStyleSheet, offset))) {
    			newStyleSheet.replace(offset, imageSource.cap(1).size(), localSource);
    			offset += localSource.size();
    	// change the .css file value w.r.t. to screen resolution 
    	if((ratio <1.0) && (ratio > 0) ) {
    		QRegExp sizeRx("(\\d+)px");
    		int offset = 0;
    		while (-1 != (offset = sizeRx.indexIn(newStyleSheet, offset))) {
    			int val = sizeRx.cap(1).toInt();
    			int sizeOffset = sizeRx.cap(1).size();
    			if (val > 1) {
    				val *= ratio;
    				QString newSize = QString("%1").arg(val);
    				newStyleSheet.replace(offset, sizeRx.cap(1).size(), newSize);
    				sizeOffset = newSize.size();
    			offset += sizeOffset;
        qobject_cast<QApplication *>(QApplication::instance())->setStyleSheet(newStyleSheet);

  • Hi Yash001,
    Thanks a lot for your answer, I think this is the way to load .css file to the whole application, right?

    What I wanted to do is to load elements to my help menu only, separated from the rest of the application (which I did with .qhp file above), the final goal is to load help menu with .qhc file & QHelpEngine class, like what is described here:

    The problem is the <file></file> tag doesn't seem to be properly loaded, since I cannot see any medias when the .html files are called, neither the .css format.

    Am I missing something at that point?

  • Hi,
    I'm making a bit progression on my program.
    In fact, I realize that my .qhc file works great with Qt Assistant, which I try with this command:
    assistant -collectionFile helpmenu.qhc
    Every videos, images, css style, and fonts are properly loaded.

    However, in my application, when I loaded the same helpmenu.qhc with QHelpEngine using:
    QHelpEngine(const QString &collectionFile, QObject *parent = 0);
    Not everything was properly loaded (images yes, but no videos, and still no .css style), do I have to load it also on my .qrc file?
    Please, if someone have an idea, let me know.

  • @huy-cong I am trying to load my mp4 video into qt assistant, but I just get the message "Your browser does not support HTML video. ".

    I am using Qt 5.13 and the html I am using to load the video is:

    <video width="400" controls>
    <source src="videos/mov_bbb.mp4" type="video/mp4">
    <source src="videos/mov_bbb.ogg" type="video/ogg">
    Your browser does not support HTML video.

    Can you tell me how you embedded your video in your .html file?


Log in to reply