Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
4.7.1
-
None
Description
I have a complex style sheet for my application. We do many changes there, even depending on custom properties.
so my style sheets looks like this:
@
QLineEdit
{
selection-background-color: rgb(51,102,211);
selection-color: rgb(255,255,255);
border: 1px solid rgb(138,138,138);
background: rgb(255,255,255);
color: rgb(0,0,0);
padding-left: 1px; /* 3 px away from left border (pg 72) */
padding-right: 2px;
padding-bottom: 2px; /* 4 pixels from bottom border */
padding-top: 0px;
max-height: 14px;
min-height: 14px;
}
QLineEdit[error="true"]
{
background: rgb(255,193,207);
}
@
Then I have a custom QLineEdit derived class like this:
@
class CqLineEdit : public QLineEdit
{
Q_OBJECT
Q_PROPERTY(bool error READ isError WRITE setError NOTIFY updateStyle)
...
}
void CqLineEdit::setError(bool bValue)
{
m_bError = bValue;
emit updateStyle();
}
@
What I would expect is that the visual representation of the line edit would switch, when I change the property error from true to false and vice versa (background color red or white). But the only possibility I found to solve this up to now is using internals of Qt:
@
#include <QtGui/private/qwidget_p.h>
#include <QtGui/private/qstylesheetstyle_p.h>
class QETWidget : public QWidget
{
public:
void RepolishStyleSheet(bool bRecursive = true)
};
void CqLineEdit::setError(bool bValue)
{
m_bError = bValue;
QETWidget* pEtWidget = (QETWidget*)this;
pEtWidget->RepolishStyleSheet();
}
@
This works if the qwidget_p.h is included as QETWidget is a friend class of QWidget ;-( But I would prefer a solution using only the public API. Any ideas on how to solve that?
####################################
The only solution I found was this:
I stumbled over something in the "faq":http://developer.qt.nokia.com/faq/answer/how_can_my_stylesheet_account_for_custom_properties but from my perspective, this is not a nice solution ;-(
Reaplying the style sheet is not an option, as the style sheet is about 3.500 lines and is applied at application level. I don't want to set the style sheet on app level for each property change in a widget. I will live with the unpolish/repolish solution as I found no other...
#########################################
What I would expect ios some "magic" that binds the widgets proerty change notification to a style sheet repolish The current possibility is a bit strange in my eyes.
There is a corresponding forum thread: http://developer.qt.nokia.com/forums/viewthread/10200/