[Qt] Qt stylesheets and URL problem

Marcin Dębicki alterfenix at gmail.com
Tue Dec 22 16:39:53 CET 2009


Ok, that isn't the case:-) Since I am running out of ideas I will
provide some more info. I haven't found any information how url param
is processed by Qt so I assumed that it's relative url and current
directory is the point of origin.
I have taken taken the sample stylesheet from Qt package, copied all
images to right place (so relative urls lead to existing items).
Now I also have checked what happens if I provide absolute path (like
c:/img.png) and this time it worked. However I shouldn't distribute
application themes containing absolute paths to images (on Windows it
would be messy) so the question is how can I properly handle relative
paths

Best regards,
Marcin Dębicki

2009/12/22 zeljko <zeljko at holobit.net>:
> On Monday 21 December 2009 22:38, Marcin Dębicki wrote:
>> I have code:
>>
>> s:=TStringList.Create;
>>   s.LoadFromFile(fname);
>>   w:=s.Text;
>>   Dir := GetCurrentDir;
>>   SetCurrentDir(ExtractFilePath(fname));
>>   QApplication_setStyleSheet(QApplicationH(QCoreApplication_instance), @w);
>>   SetCurrentDir(Dir);
>>   s.Free;
>>
>> Where w is a widestring. I am trying to load custom stylesheet with
>> urls to pngs for some controls (checkboxes and so on). Problem is that
>> for some reason no images are loaded. So the question is does Qt need
>> some additional library to handle png files? image plugins are
>> properly loaded (I use webview there also).
>> Additionally I have looked into bindings source and I see:
>>
>> void QApplication_setStyleSheet(QApplicationH handle, PWideString sheet)
>> {
>>       QString t_sheet;
>>       copyPWideStringToQString(sheet, t_sheet);
>>       ((QApplication *)handle)->setStyleSheet(t_sheet);
>> }
>>
>> while according to this (working example):
>>
>> QFile file(":/qss/" + sheetName.toLower() + ".qss");
>>     file.open(QFile::ReadOnly);
>>     QString styleSheet = QLatin1String(file.readAll());
>>
>>     ui.styleTextEdit->setPlainText(styleSheet);
>>     qApp->setStyleSheet(styleSheet);
>>
>> There should be non unicode string passed
>
> Well, you can go around it, but I doubt that it is a problem.
>
>  s:=TStringList.Create;
>   s.LoadFromFile(fname);
>   w := UTF8Encode(s.Text);
>   Dir := GetCurrentDir;
>   SetCurrentDir(ExtractFilePath(fname));
>   QApplication_setStyleSheet(QApplicationH(QCoreApplication_instance), @w);
>   SetCurrentDir(Dir);
>   s.Free;
>
>
>
> _______________________________________________
> Qt mailing list
> Qt at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/qt
>




More information about the Qt mailing list