Local library: Improvements on QClickableLabel

This commit is contained in:
Nicolas Mailloux 2022-06-23 19:15:33 -04:00
parent ccdc1a235c
commit 694466444e
3 changed files with 14 additions and 9 deletions

View file

@ -51,21 +51,18 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
// Horizontal layout that will contain the book button and its icon
QHBoxLayout * horizontalLayout = new QHBoxLayout(this);
// Book icon
// Book icon label
bookIconArray[i] = new QLabel(this);
bookIconArray[i]->setStyleSheet("padding: 20px");
// Book button
bookBtnArray[i] = new QClickableLabel(this);
bookBtnArray[i]->setProperty("type", "borderless");
bookIconArray[i]->setStyleSheet("padding: 20px");
bookBtnArray[i]->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 20px");
bookBtnArray[i]->setFont(QFont("u001"));
// Spacer
QSpacerItem * horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
horizontalLayout->addWidget(bookIconArray[i]);
horizontalLayout->addWidget(bookBtnArray[i]);
horizontalLayout->addSpacerItem(horizontalSpacer);
ui->booksVerticalLayout->addLayout(horizontalLayout);
}
setupBooksList();

View file

@ -7,6 +7,12 @@ QClickableLabel::QClickableLabel(QWidget* parent, Qt::WindowFlags f)
QClickableLabel::~QClickableLabel() {}
void QClickableLabel::mousePressEvent(QMouseEvent* event) {
void QClickableLabel::mousePressEvent(QMouseEvent * event) {
emit clicked();
QClickableLabel::setStyleSheet("color: white; background-color: black; border-radius: 10px; padding: 20px");
}
void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) {
emit unclicked();
QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 20px");
}

View file

@ -14,9 +14,11 @@ public:
signals:
void clicked();
void unclicked();
protected:
void mousePressEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event);
};