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. setStyleSheet via .qss file

setStyleSheet via .qss file

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

    mainwindow constructor:

    QFile file(":/Darkeum.qss");
    file.open(QFile::ReadOnly);
    QString styleSheet = QLatin1String(file.readAll());
    setStyleSheet(styleSheet);
    

    Darkeum.qss is in the project folder, and I also add it to the .pro file:

    DISTFILES += \
        Darkeum.qss
    

    I am getting this error: QIODevice::read (QFile, ":\Darkeum.qss"): device not open

    If I am using the full file path it is working: "C:/...../Darkeum.qss"

    jsulmJ 1 Reply Last reply
    0
    • E ekato993

      @jsulm

      That also not working.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @ekato993 Use resources as I suggested or construct absolute path to the file at runtime (using relative paths is dangerous as you can see, they depend on current working directory): https://doc.qt.io/qt-5/qstandardpaths.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      E 1 Reply Last reply
      1
      • E ekato993

        mainwindow constructor:

        QFile file(":/Darkeum.qss");
        file.open(QFile::ReadOnly);
        QString styleSheet = QLatin1String(file.readAll());
        setStyleSheet(styleSheet);
        

        Darkeum.qss is in the project folder, and I also add it to the .pro file:

        DISTFILES += \
            Darkeum.qss
        

        I am getting this error: QIODevice::read (QFile, ":\Darkeum.qss"): device not open

        If I am using the full file path it is working: "C:/...../Darkeum.qss"

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @ekato993 said in setStyleSheet via .qss file:

        QFile file(":/Darkeum.qss");

        How should this path work?
        If you want to use a relative path then do (I assume the file is next to the executable and that that folder is working directory):

        QFile file("Darkeum.qss");
        

        But you should consider to use https://doc.qt.io/qt-5/resources.html

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        E 1 Reply Last reply
        1
        • jsulmJ jsulm

          @ekato993 said in setStyleSheet via .qss file:

          QFile file(":/Darkeum.qss");

          How should this path work?
          If you want to use a relative path then do (I assume the file is next to the executable and that that folder is working directory):

          QFile file("Darkeum.qss");
          

          But you should consider to use https://doc.qt.io/qt-5/resources.html

          E Offline
          E Offline
          ekato993
          wrote on last edited by
          #3

          @jsulm

          That also not working.

          jsulmJ 1 Reply Last reply
          0
          • E ekato993

            @jsulm

            That also not working.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @ekato993 Use resources as I suggested or construct absolute path to the file at runtime (using relative paths is dangerous as you can see, they depend on current working directory): https://doc.qt.io/qt-5/qstandardpaths.html

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            E 1 Reply Last reply
            1
            • jsulmJ jsulm

              @ekato993 Use resources as I suggested or construct absolute path to the file at runtime (using relative paths is dangerous as you can see, they depend on current working directory): https://doc.qt.io/qt-5/qstandardpaths.html

              E Offline
              E Offline
              ekato993
              wrote on last edited by
              #5

              @jsulm

              With resource file it is working thanks.

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved