StyleSheet set is slow
-
HI,
I tried to set the style sheet. It gets effected, but takes a second to update in UI.
I am trying to change border on mouse press. I need to keep my widget pressed for a second for the change to appear@void PosButton::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << Q_FUNC_INFO << "Invoked";if(rect().contains(event->pos())) { qDebug() << Q_FUNC_INFO << "Emit click"; emit clicked(this->objectName()); } m_pBaseWidget->setStyleSheet("QFrame#baseWidget {" "border: 1px solid black;" "border-top-width: 0;" "border-left-width: 0;" "border-style: outset;}" ); qDebug() << Q_FUNC_INFO << "Exits"; return;
}
void PosButton::mousePressEvent(QMouseEvent *event)
{
qDebug() << Q_FUNC_INFO << "Invoked";
Q_UNUSED(event);m_pBaseWidget->setStyleSheet("QFrame#baseWidget {" "border: 2px solid orange;" "border-top-width: 0;" "border-left-width: 0;" "border-style: outset;}" ); qDebug() << Q_FUNC_INFO << "Exits"; return;
}@
PosButton is derived from QWidget. I am trying to set style for the QFrame baseWidget inside it.
Also I tried setting property and change but I'm not sure if the style sheet statement I use is in right way
@PosButton[pressed="true"] QFrame#baseWidget
{
border: 2px solid orange;
border-top-width: 0;
border-left-width: 0;
border-style: outset;
}PosButton[pressed="false"] QFrame#baseWidget
{
border: 1px solid black;
border-top-width: 0;
border-left-width: 0;
border-style: outset;
}
@ -
Hi,
Might be a silly question but, why don't you style a QPushButton ?
-
SGaist,
I use this class as multiple types of buttons.. It has 4 labels of which one has image set on it. In total it is a customized button. So I am forced to use a custom widget instead of QPushButton.
-
Thanks,
I resolved this issue by setting a timer on the mouse release. The timeout will reset the style of the button
@void PosButton::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << Q_FUNC_INFO << "Invoked";if(rect().contains(event->pos())) { qDebug() << Q_FUNC_INFO << "Emit click"; emit clicked(this->objectName()); } QTimer::singleShot(150, this, SLOT(styleTimeout())); qDebug() << Q_FUNC_INFO << "Exits"; return;
}
void PosButton::mousePressEvent(QMouseEvent *event)
{
qDebug() << Q_FUNC_INFO << "Invoked";
Q_UNUSED(event);m_pBaseWidget->setStyleSheet("QFrame#baseWidget {" "border: 2px solid orange;" "border-top-width: 0;" "border-left-width: 0;" "border-style: outset;}" ); qDebug() << Q_FUNC_INFO << "Exits"; return;
}
void PosButton::styleTimeout()
{
qDebug() << Q_FUNC_INFO << "Invoked";if (NULL != m_pBaseWidget) { qDebug() << Q_FUNC_INFO << "set style"; m_pBaseWidget->setStyleSheet("QFrame#baseWidget {" "border: 1px solid black;" "border-top-width: 0;" "border-left-width: 0;" "border-style: outset;}" ); } qDebug() << Q_FUNC_INFO << "Exits"; return;
}@