I need to create a button which may contain two icons and two text label to display (on screenshots - every line such as "Email" or "Connection" is a standalone button).
From what I understood - I can't override QPushButton or QAbstractButton and I have to implement my own custom widget in order to achieve such layout. So far I'm trying to make such buttons with Qt Designer and change style of the widget using QSS and dynamic properties but for some reason stylesheet is not changing when I press the button. My code:
namespace ui
{
ViewEntryPushButton::ViewEntryPushButton(QWidget* parent)
: QWidget(parent)
, ui(new Ui::ViewEntryPushButton)
{
ui->setupUi(this);
}
ViewEntryPushButton::~ViewEntryPushButton()
{
delete ui;
}
void ViewEntryPushButton::mousePressEvent(QMouseEvent* event)
{
this->setProperty("pressed", true);
this->style()->unpolish(this);
this->style()->polish(this);
this->update();
}
void ViewEntryPushButton::mouseReleaseEvent(QMouseEvent *event)
{
this->setProperty("pressed", false);
this->style()->unpolish(this);
this->style()->polish(this);
this->update();
}
} // namespace ui
And my style sheet which I apply to the highest object in Qt Designer object view:
#ViewEntryPushButton {
background-color: transparent;
padding: 5px;
margin-left: 5px;
}
#ViewEntryPushButton[pressed="true"]{
background-color:rgb(51, 0, 255);
border-width: 3px;
border-color: rgba(255, 255, 255, 20);
border-style: inset;
}
So my questions:
1. Is my approach right or it is possible to subclass QAbstractButton and implement it like this?
2. What am I doing wrong with style sheets in this case and why style of the widget is not changing when I press my mouse?


