Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2009-12

Qt stylesheets and URL problem

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcin Dębicki

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

Best regards,
Marcin D?bicki

zeljko
to Marcin Dębicki
Marcin D?bicki wrote 35 lines
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;
Marcin Dębicki
to zeljko

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 :

Show quoted text 55 lines
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 http://lists.lazarus.freepascal.org/mailman/listinfo/qt