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. Stylesheet in QTreeWidget Change Arrow Images from .qrc
Qt 6.11 is out! See what's new in the release blog

Stylesheet in QTreeWidget Change Arrow Images from .qrc

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.5k Views 2 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
    shathcock
    wrote on last edited by
    #1

    So I have my QTree widget exactly like I want it but I have one thing that I would like to do. The following code allows me to have white arrows on a black background as long as the .png files are in the build directory.

    ui->treeWidgetProcs->setStyleSheet("QTreeView { background: black; color: white; }
    QTreeView::branch { background: black; }
    QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(branch-closed.png); }
    QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(branch-open.png); }");

    I also have the two .png files in the .qrc file that I have in my project that contains my icon however it doesn't work. There is no prefix assigned to any of the files.

    ui->treeWidgetProcs->setStyleSheet("QTreeView { background: black; color: white; }
    QTreeView::branch { background: black; }
    QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(:/branch-closed.png); }
    QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(:/branch-open.png); }");

    Can anyone see what I am doing wrong or will this just not work? Thanks in Advance!

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Make sure the path is correct by e.g. checking if the resource file exists with QFile::exists().

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • S Offline
        S Offline
        shathcock
        wrote on last edited by
        #3

        Yes the file does exist and I am getting my window Icon from the file and that is working fine. I checked and both of the png files are referenced in the qrc file. I looked at the .ui code for mainwindow and it specifies a

        <iconset resource="icons.qrc">

        where it loads my Icon. Do I need to specify a resource file to use in code somewhere before using the resources?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Can you share the .qrc file content ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shathcock
            wrote on last edited by
            #5

            Sure

            <RCC>
            <qresource prefix="/">
            <file>DXT.ico</file>
            <file>branch-closed.png</file>
            <file>branch-open.png</file>
            </qresource>
            </RCC>

            Christian EhrlicherC 1 Reply Last reply
            0
            • S shathcock

              Sure

              <RCC>
              <qresource prefix="/">
              <file>DXT.ico</file>
              <file>branch-closed.png</file>
              <file>branch-open.png</file>
              </qresource>
              </RCC>

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @shathcock Did you really wrote url(:/branch-closed.png); and not by accident e.g. url( :/branch-closed.png ); or similar?
              Please provide a minimal, compilable example.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              S 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @shathcock Did you really wrote url(:/branch-closed.png); and not by accident e.g. url( :/branch-closed.png ); or similar?
                Please provide a minimal, compilable example.

                S Offline
                S Offline
                shathcock
                wrote on last edited by
                #7

                @Christian-Ehrlicher I'm positive I have tried it at least 10 times. I'll have to get a compilable example together I assume you mean a complete project. How should I include it in the forum I have never done that before and it will take me some time to get it together.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  shathcock
                  wrote on last edited by
                  #8

                  Ok I solved the problem. I added a prefix to the images and now use :/arrows/xxxx.png and it works fine! Thanks for the help everyone!!

                  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