I would be inclined to make the QLabels look after their own highlighting when the mouse is over them.
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QLabel>
#include <QPixmap>
#include <QGraphicsDropShadowEffect>
{
Q_OBJECT
public:
{
pixmap.
fill(QColor("mediumseagreen"));
setPixmap(pixmap);
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(10);
shadow
->setColor
(QColor("orchid"));
setGraphicsEffect(shadow);
}
protected:
void enterEvent
(QEvent *event
) {
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(10);
shadow
->setColor
(QColor("lightsalmon"));
setGraphicsEffect(shadow);
}
void leaveEvent
(QEvent *event
) {
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(10);
shadow
->setColor
(QColor("orchid"));
setGraphicsEffect(shadow);
}
};
{
Q_OBJECT
public:
{
layout->addWidget(new Label);
layout->addWidget(new Label);
}
};
int main(int argc, char **argv)
{
Widget w;
w.show();
return app.exec();
}
#include "main.moc"
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QLabel>
#include <QPixmap>
#include <QGraphicsDropShadowEffect>
class Label: public QLabel
{
Q_OBJECT
public:
Label(QWidget *p = 0): QLabel(p)
{
QPixmap pixmap(200, 200);
pixmap.fill(QColor("mediumseagreen"));
setPixmap(pixmap);
setFrameStyle(QFrame::Box);
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(10);
shadow->setColor(QColor("orchid"));
setGraphicsEffect(shadow);
}
protected:
void enterEvent(QEvent *event)
{
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(10);
shadow->setColor(QColor("lightsalmon"));
setGraphicsEffect(shadow);
}
void leaveEvent(QEvent *event)
{
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(10);
shadow->setColor(QColor("orchid"));
setGraphicsEffect(shadow);
}
};
class Widget: public QWidget
{
Q_OBJECT
public:
Widget(QWidget *p = 0): QWidget(p)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(new Label);
layout->addWidget(new Label);
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks