[Interest] CSS class only works in designer, not during runtime

Philipp Kursawe phil.kursawe at gmail.com
Thu Oct 31 16:11:39 CET 2013


And here is an application wide version of this:

bool YourApp::eventFilter(QObject* object, QEvent* event) {
  if (event->type() == QEvent::DynamicPropertyChange) {
    auto changeEvent = static_cast<QDynamicPropertyChangeEvent*>(event);

    if (changeEvent->propertyName() == "class") {
      if (auto widget = qobject_cast<QWidget*>(object)) {
        widget->style()->unpolish(widget);
        widget->style()->polish(widget);
        widget->update();
      }
    }
  }
  return __super::eventFilter(object, event);
}


On Thu, Oct 31, 2013 at 3:55 PM, Philipp Kursawe <phil.kursawe at gmail.com>wrote:

> Well, it seems these 3 lines solve the issue:
>
> widget->style()->unpolish(widget);
> widget->style()->polish(widget);
> widget->update();
>
> However this should be handled by the QWidget internally, when it knows
> that a dynamic property is used in a style.
>
>
> On Thu, Oct 31, 2013 at 3:18 PM, Philipp Kursawe <phil.kursawe at gmail.com>wrote:
>
>> I want to style my QLineEdit in case of an error like this:
>>
>> QLineEdit.error { border: 2px solid orange; }
>>
>> I have set this style on the QLE parent widget. When I add the dynamic
>> "class" property in the designer and set it to "error" the QLE gets a nice
>> thick orange border.
>> However if I do the same in code:
>> edit->property("class", "error")
>> the QLE does not change its border.
>>
>> Any ideas? Do I need to force it to refresh?
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131031/72d8693f/attachment.html>


More information about the Interest mailing list