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 specify images from different directories than the application startup directory
Forum Updated to NodeBB v4.3 + New Features

How to specify images from different directories than the application startup directory

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 2.3k 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.
  • D Offline
    D Offline
    Dimitrios Tsobanopoulos
    wrote on last edited by
    #1

    Hello,

    I am looking for a way to specify images in styles that will be read in from the current directory, and not from the directory the application starts.
    Here is part of a style I currently use:
    @QScrollBar::down-arrow:vertical {
    width: 9px;
    height: 10px;
    background: transparent;
    image: url(./scr_down_arrow.png);
    }@

    Is there a way to modify the url(...) so that it will load from the current directory ?

    Thanks

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      You might be able to do this by setting the applications working directory to the current directory, see QDir::setCurrent(), so paths gets resolved relative to the current directory.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dimitrios Tsobanopoulos
        wrote on last edited by
        #3

        Yes, I thought of this, and the application is started with a command like this:
        @./someotherdir/startdir/myapp@
        The current directory is not where the application is located, but Qt seems to always use the startup directory for picking up resource images from the filesystem. However, I'll check again in the code to make sure where the application thinks it is on startup.
        Thanks.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          q8phantom
          wrote on last edited by
          #4

          This might help you a little bit

          http://stackoverflow.com/questions/7402576/how-to-get-current-working-directory-in-a-qt-application

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dimitrios Tsobanopoulos
            wrote on last edited by
            #5

            At the C++ level, QT::currentPath() indeed returns the current directory, however, this does not solve the problem of the Qt style module always using the directory where the binary is located. I was looking for a quick solution, something that I may have missed in the manuals describing style syntax. Someone might ask 'why aren't you packing everything in the resources', well, the objective is to have different, and possibly user-supplied resources in different directories, so when the application is started from one of them, the resources in the current directory will be used. If it turns out that this is not supported at all, then I'll need to revise this part of the design entirely.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              Is there something wrong with this approach:
              @
              QString styles = QString(
              "QScrollBar::down-arrow:vertical { ...; image: url(%1/scr_down_arrow.png); }"
              "QScrollBar::up-arrow:vertical { ...; image: url(%1/scr_up_arrow.png); }"
              ).arg(basePath);
              whatever.setStyleSheet(styles)
              @

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dimitrios Tsobanopoulos
                wrote on last edited by
                #7

                Thank you, all. I finally used a variation of the approach suggested by ChrisW67 namely, adding a marker at the beginning of the path for each image and then replacing them all with the appropriate path just before applying the style.

                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