Static library don't see image paths
-
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
-
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
@AndrzejB your library needs to use Q_INIT_RESOURCE
-
-
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.qrcsecond , smaller problem - I don't know why icons on buttons is so small?
-
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.qrcsecond , smaller problem - I don't know why icons on buttons is so small?
-
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.qrcsecond , smaller problem - I don't know why icons on buttons is so small?
@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)?
-
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
Here is comparing: my application with big button and snall icon and below original icon scaled 100% in Gimp. -
What is the button final size ?
-
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.
-
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
Here is comparing: my application with big button and snall icon and below original icon scaled 100% in Gimp.@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.