PyQt - Error while setting QLineEdit background from image - css

I searched all over the internet for a solution for this, but found nothing.
Basicly I have a QLineEdit name 'le' (inside a class) whose background I want to set as an image. Using the code bellow, i get the error "Could not parse stylesheet of widget 0x1867580" and the image is not dispalyed.
self.le = QtGui.QLineEdit(self)
self.le.move(300,300)
self.le.setFrame(False)
self.le.setFixedWidth(100)
self.le.setStyleSheet("background: url:(Try.png)")
The Try.png image is a 100x20 px image, so it was supposed to fit that particular QLineEdit.
Does anyone have a clue about what might be going on?
Many thanks in advance,
Miguel

Try
self.ls.setStyleSheet("background-image: url(Try.png);")
but Try.png must be in folder from which Qt app started. Unless it is a resource, then
self.ls.setStyleSheet("background-image: url(:/images/try);")
where images is name of resource group
<qresource prefix="/images">
<file alias="try">Try.png</file>
</qresource>
then the image will be compiled into the app.

Related

Qt does not show images

Problem show in the link below:
http://postimg.org/image/sp9mm85qb/
I try to add this image in code
QIcon iconmain("qrc:/img/main.png");
ui->tabWidget->tabBar()->setTabIcon(1,iconmain);
Tried to add image from resourse file from disk. But it still invisible.
I assume the image is in the resource file with the prefix img, so you would access it without the qrc text prefix: -
QIcon iconmain(":/img/main.png");
Solved by changing msvs compil to mingv

Weid layout when loading SWF with QWebView

After a bit of research I wasn't really able to understand why this happens.
In a nutshell, I'm calling QWebView and feeding a .swf into it and it works. However it goes out of its frame/layout, and I'm not sure why.
For a representation, see:
As you may see, the dark greyish rectangle is where QWebView was placed, however the .swf going into it is represented out of it in the top left corner.
How to recreate this problem:
I literally just placed a QWebView using the designer, added all the includes needed etc. and added 3 lines of code to mainwindow.cpp :
QWebSettings *settings = ui->webView->settings();
settings->setAttribute(QWebSettings::PluginsEnabled, true);
ui->webView->load(QUrl("http://www.w3schools.com/html/bookmark.swf"));
I also tried opening an html file with the .swf wrapped in it, but the same problem occurs.
Am I doing something wrong? Is it a known bug? Thanks in advance.
Apparently this is a known bug with Qt, will be fixed next release.
Source: https://bugreports.qt-project.org/browse/QTBUG-33053
What I did to fix was basically compile QT again with the fix included.

Display a PNG image as is on an Android View (assistant allows only icons)

I'm trying to create an Android View with a PNG image displayed as is in it. The only problem is, when I use the "ImageView" option, it will only allow me to create icons (Launcher icon, menu icon...etc.), which are too small to be displayed on my View!
I tried importing the PNG file in the drawable folders manually with "Link to file in the file system" option in the advanced options. That way, it does appear in the Graphical Layout of Eclipse as I want it to, but the XML file refers to a resource android:src="#drawable/myImage.png" that is "not found".
How to solve this?
Thank you in advance.
SOLVED **
Actually, what I did is enter the resource manually in the XML file of my activity as such:
<ImageView
android:src="#drawable/myimage" />
I put the file in all the drawable folders (xhdpi, hdpi, ldpi and mdpi) but in different sizes (200px width for ldpi, 300 for mdpi, 400 for hdpi and 480 for xhdpi). All files' name is myimage.png (but you should not put the extension in the code above!
PS: The reason for which it wasn't working before is that the file name's first letter was capital. I think...
Thanks anyway.
Sorry 'bout editing first post, but the site won't allow me to "answer my own question cuz I'm a newbie". :)

Icon not shown on other PC

im developing QT application, and im using few icons
this is my resource.qrc file
<RCC>
<qresource prefix="/new/prefix1">
<file>army-officer-icon.png</file>
<file>uac.png</file>
</qresource>
</RCC>
then i ofcourse include it in my .pro file
RESOURCES += \
resource.qrc
and here is the code which takes care of icons:
//this code is part of the mainwindow.cpp
QSystemTrayIcon *trayIcon;
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/new/prefix1/army-officer-icon.png"));
trayIcon->show();
//this code is part of the ui_mainwindow.h (generated by QT)
QLabel *label_5;
label_5 = new QLabel(centralWidget);
label_5->setObjectName(QString::fromUtf8("label_5"));
label_5->setGeometry(QRect(40, 302, 46, 21));
label_5->setPixmap(QPixmap(QString::fromUtf8(":/new/prefix1/uac.png")));
label_5->show();
So, this looks reasonable, right ?
===windows 7, developing station, QT installed
also the result effect is as i expected
i can see both icons :: tray icon & uac shield = awesome
but when i move to the other workstation, somethings strange happens
===windows XP, user work station, QT NOT installed
as u can see, the trayicon still has its own icon, but the "uac shield icon" dissapears... its very disturbing, and i really dont get it since both icons are *.png formats, i browsed a lot, and maybe it has connection with qt image plugins (althought i think that i should care about it only when my icon are *.jpeg, *.gif format), but wasnt able to make this solution works...
so any ideas are welcomed.
Thanx in advance.
Okay, ive found the solution just after ive posted this (actually , i was quite close, but i copied something with wrong path :/)
locate C:\QtSDK\Desktop\Qt\4.8.0\mingw\plugins
copy plugins/imageformats to your application folder
open main.cpp and add this line of codes
a.addLibraryPath(QCoreApplication::applicationDirPath ()+"/plugins");
compile, and have a look at your beautiful icons :)

Why does Qt constantly print "couldn't create image from" for SVGs?

I would like to use SVGs in menus and buttons around a Qt-4.7 application. The images are rendered correctly across linux and windows platforms, however an obnoxious message reading...
couldn't create image from ""
...is printed to the console seemingly as soon as one of these images is loaded or changes state (like highlighting or disabling its container widget). Over the course of the run of the application, many of these lines are printed, leaving a lot of senseless output crufted around reasonable application output.
Poking around the Qt code a bit, this appears to be coming from svg/qsvghandler.cpp:2680 where the line contains the following.
qDebug()<<"couldn't create image from "<<filename;
From the documentation for qDebug, you would think that I could block this by defining QT_NO_DEBUG_OUTPUT at compiletime, but this will only block the application's compiled debug calls, not the one in Qt's SVG library.
So I guess my question is actually two-fold:
As in the title, why is Qt printing this even when rendering SVGs correctly?
Without recompiling Qt or its SVG library, how do I prevent Qt from printing this and crufting the application's output?
I've also posted this question on the QtCentre forums.
To #2: You can prevent qDebug output by using qIntallMsgHandler and writing a handler that just discard the message. Also see this question: How to redirect qDebug, qWarning, qCritical etc output?
Re #1: I'm no expert on SVG but from the Qt source code where that line appears, it looks like Qt is trying to load an image file referenced in an xlink:href attribute. The output you see would seem to indicate that either the value for that attribute is "" or the value is a bunch of white space characters enclosed in "" which is removed by a call to QString.trimmed() which is then used as the name of an image file to be loaded into a QImage. I can't quite discern if the filename is ending up as an empty string or two quotes :)
I would have to guess that either the SVG files you have are filled with empty string xlink:href attributes (probably links or filenames for texture images) or there is something about the SVG file causing Qt to incorrectly parse it. I would lean towards the former.
What is your criteria for concluding that they are being rendered correctly? Perhaps you could open the SVG files in a text editor and look at the xlink:href occurances in it?
I've had a similar issue, I used Adobe Illustrator to create images and then save as SVG. The problem is that hidden layers in Illustrator still gets written to the SVG file, but its display property is set to "none". In my case a hidden layer of a file I "placed" - to get an idea if the background I'm creating would look OK.
This causes your image to render correctly as you say, but Qt complains about the missing invisible layer in the SVG file. If you open the SVG file in a text viewer you might find the hidden layer looks something like this:
<g id="bglogo_x5F_splash" style="display:none;">
<image style="display:inline;overflow:visible;" width="1740" height="438" xlink:href="../logo_preview.png" transform="matrix(1 0 0 1 154 409)">
</image>
</g>
Qt will complain about the missing "../logo_preview.png" file.
Hope this helps

Resources