Solved Could not parse stylesheet of object QLabel
-
@oBOXPOH said in Could not parse stylesheet of object QLabel:
I tried to use signals and slot, but no success
What did you try?
The idea is to send a signal from the second thread to trigger the style change in your GUI thread (so you avoid any conflict). -
@JonB said in Could not parse stylesheet of object QLabel:
@oBOXPOH
I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.Define a signal in the thread.
emit
the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UIconnect()
the thread's signal to the UI's slot. There act on the signal and its parameters to execute thepLabel->setStyleSheet()
.As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.
Ok. But where can I find the main UI thread? Just I created slot for changing in MainWindow.cpp - and I still have my problem...
Let me explain, what I have. I have MainWindow class, where I create 2 widgets. In the second widget I have some another widgets. When I activate button of the first widget, I start the thread, where I get requests to change some properties of widgets in second widget. For example, I can change text for labels, but can't change styles of labels.
-
@oBOXPOH Can you have look at Signals/slots accross threads
Hope this might explain you a bit.All the best.
-
@oBOXPOH said in Could not parse stylesheet of object QLabel:
I start the thread
But do you really need the thread? You dont need an extra thread just to change widget properties
-
@Pl45m4 said in Could not parse stylesheet of object QLabel:
@oBOXPOH said in Could not parse stylesheet of object QLabel:
I start the thread
But do you really need the thread? You dont need an extra thread just to change widget properties
I think, I need the thread, because I use QSerialPort to send and read messages. If I won't use the thread, I will block the widget, where I create the thread.
-
@oBOXPOH
No, Qt classes like serial ports are asynchronous. So long as you use the signals/slots, not blocking calls. It seems unlikely you need a secondary thread, and without multiple threads your life will be much easier.... -
If you are currently using the blocking
QSerialPort
approach (withwaitFor...()
), have a look at the non-blocking example: -
@Pl45m4 said in Could not parse stylesheet of object QLabel:
@JonB said in Could not parse stylesheet of object QLabel:
serial ports are asynchronous
Not always. There is a blocking and non-blocking QSerialPort appraoch.
I'm not following you? I wrote
No, Qt classes like serial ports are asynchronous. So long as you use the signals/slots, not blocking calls.
The calls are asynchronous. If you choose to
waitFor..()
you are choosing to block, by making your code synchronous. What are you saying any different from that? -
@JonB said in Could not parse stylesheet of object QLabel:
@oBOXPOH
I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.Define a signal in the thread.
emit
the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UIconnect()
the thread's signal to the UI's slot. There act on the signal and its parameters to execute thepLabel->setStyleSheet()
.As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.
I can't to win my problem with styleSheet... I even deleted thread. Let me explain what I have done.
When I click to button1_1, I emit some signal from widget1 to slot of widget2. In slot of widget2 I emit some signal to slot of created some class inside widget2. Inside this class I have a loop with signals/slots. And during this loop I need to change styles of widgets inside widget2 (label2_1). When I need to change style of label, I emit signal from class to slot of widget2 and call method of, for example, widget2_1 in order to change the style of label, but, without exception, I get "Could not parse stylesheet of object QLabel(0xf66ad8)". I tried many things, but still no success.Hope for your help! Thank you in advance!
-
Hi
can you show the complete stylesheet?
as that errors says it cannot be parsed so it might just be a case of invalid syntax. -
@mrjj said in Could not parse stylesheet of object QLabel:
Hi
can you show the complete stylesheet?
as that errors says it cannot be parsed so it might just be a case of invalid syntax.pLabel->setStyleSheet(QString(pCChar_GreenStatusStyle));
const char *pCChar_GreenStatusStyle = "{ color: green; font-weight: bold; }";
-
@mrjj said in Could not parse stylesheet of object QLabel:
Hi
can you show the complete stylesheet?
as that errors says it cannot be parsed so it might just be a case of invalid syntax.You are right, by the way! I need:
const char* *pCChar_GreenStatusStyle = "QLabel { color: green; font-weight: bold; }";
And now it works finally! By the way, I deleted this QLabel word because I tried to find an error.
Anyway, If someone has such problem, try to use only signals and slots like I used (image and description above) and check your styles. For serialPorts, for example, don't use threads, because else you will be in trouble.
-
@oBOXPOH said in Could not parse stylesheet of object QLabel:
I need:
const char* *pCChar_GreenStatusStyle = "QLabel { color: green; font-weight: bold; }";
I am surprised at this! That is a
char **
. But if you say that is required to work.....