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. Static library don't see image paths
Forum Update on Monday, May 27th 2025

Static library don't see image paths

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 554 Views
  • 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.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by
    #1

    In my minimal example is main project and static library with Qt widgets.
    Both have qrc files, like

    <!DOCTYPE RCC>
    <RCC version="1.0">
    <qresource prefix="/">
        <file>1.png</file>
    </qresource>
    </RCC>
    

    whereas main app can see paths do png images,
    library can't.

    Second problem:

    although images are 48x48 and even explicit is set size to 48x48

        QIcon icon;
        icon.addFile(":1.png", QSize(48, 48));
        button->setIcon(icon);
        setCentralWidget(button);
    

    Digit "1" is too small, seems to be resized to 16x16 or 24x24).

    I have minimal example in github:minimal-examples/static-lib-res

    sierdzioS 1 Reply Last reply
    0
    • A AndrzejB

      In my minimal example is main project and static library with Qt widgets.
      Both have qrc files, like

      <!DOCTYPE RCC>
      <RCC version="1.0">
      <qresource prefix="/">
          <file>1.png</file>
      </qresource>
      </RCC>
      

      whereas main app can see paths do png images,
      library can't.

      Second problem:

      although images are 48x48 and even explicit is set size to 48x48

          QIcon icon;
          icon.addFile(":1.png", QSize(48, 48));
          button->setIcon(icon);
          setCentralWidget(button);
      

      Digit "1" is too small, seems to be resized to 16x16 or 24x24).

      I have minimal example in github:minimal-examples/static-lib-res

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @AndrzejB your library needs to use Q_INIT_RESOURCE

      (Z(:^

      1 Reply Last reply
      3
      • A AndrzejB has marked this topic as solved on
      • A Offline
        A Offline
        AndrzejB
        wrote on last edited by
        #3

        Helps

        void initLibraryResources() {
            Q_INIT_RESOURCE(2);
        }
        
        Q_CONSTRUCTOR_FUNCTION(initLibraryResources)
        

        in cpp library file.
        Is "2" because is it filename of qrc without extension: 2.qrc

        second , smaller problem - I don't know why icons on buttons is so small?

        SGaistS S 2 Replies Last reply
        0
        • A AndrzejB

          Helps

          void initLibraryResources() {
              Q_INIT_RESOURCE(2);
          }
          
          Q_CONSTRUCTOR_FUNCTION(initLibraryResources)
          

          in cpp library file.
          Is "2" because is it filename of qrc without extension: 2.qrc

          second , smaller problem - I don't know why icons on buttons is so small?

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @AndrzejB hi,

          What is the original size of the icons ?
          On which kind of button are you setting them ?
          How are you setting them ?

          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
          • A AndrzejB

            Helps

            void initLibraryResources() {
                Q_INIT_RESOURCE(2);
            }
            
            Q_CONSTRUCTOR_FUNCTION(initLibraryResources)
            

            in cpp library file.
            Is "2" because is it filename of qrc without extension: 2.qrc

            second , smaller problem - I don't know why icons on buttons is so small?

            S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            @AndrzejB said in Static library don't see image paths:

            second , smaller problem - I don't know why icons on buttons is so small?

            Do you have scaling enabled for the screen in your OS settings (e.g. 150% or 200% on Windows for a 4K display)?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AndrzejB
              wrote on last edited by
              #6

              My 1.png has size 48x48 pixels.
              I use it:

                  QPushButton *button = new QPushButton(this);
                  QIcon icon;
                  icon.addFile(":1.png", QSize(48, 48));
                  button->setIcon(icon);
                  setCentralWidget(button);
              
              

              not only png is 48x48 but also i set QSize(48,48) and icon shrinks
              shrinked1.png
              Here is comparing: my application with big button and snall icon and below original icon scaled 100% in Gimp.

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

                What is the button final size ?

                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
                • A Offline
                  A Offline
                  AndrzejB
                  wrote on last edited by
                  #8

                  At end LibWindow::LibWindow

                  qDebug()<<button->size();
                  

                  is QSize(100, 30)
                  but finally, after lw.show()

                  lw.show();
                  qDebug()<<lw.button->size();
                  

                  is QSize(200, 100)

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

                    You should check that either in the showEvent method of the class or check the size through a slot once the button is actually visible.

                    Calling show on a widget just schedules its visibility for the next round of the event loop so requesting its size right away won't give the correct result.

                    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
                    • A AndrzejB

                      My 1.png has size 48x48 pixels.
                      I use it:

                          QPushButton *button = new QPushButton(this);
                          QIcon icon;
                          icon.addFile(":1.png", QSize(48, 48));
                          button->setIcon(icon);
                          setCentralWidget(button);
                      
                      

                      not only png is 48x48 but also i set QSize(48,48) and icon shrinks
                      shrinked1.png
                      Here is comparing: my application with big button and snall icon and below original icon scaled 100% in Gimp.

                      S Offline
                      S Offline
                      SimonSchroeder
                      wrote on last edited by
                      #10

                      @AndrzejB said in Static library don't see image paths:

                      original icon scaled 100% in Gimp

                      Again, do you use display scaling? Gimp might adjust what "100%" means based on display scaling.

                      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