class HTMLButton: public QLabel {public: HTMLButton(QString s):QLabel(s){ setFrameStyle(QFrame::Panel | QFrame::Raised); setLineWidth(1); }};
class HTMLButton: public QLabel, public QEvent {public: HTMLButton(QString name): QLabel(name), QEvent(MouseButtonPress) { setAlignment(Qt::AlignCenter); setFrameStyle(QFrame::Panel | QFrame::Raised); setLineWidth(2); setMidLineWidth(2); setFixedSize(48,32); }protected: void mousePressEvent(QMouseEvent *ev){ setFrameStyle(QFrame::Panel | QFrame::Sunken); QLabel *lab = new QLabel("[Qt]"); lab->show(); } void mouseReleaseEvent(QMouseEvent *ev){ setFrameStyle(QFrame::Panel | QFrame::Raised); }};
class HTMLButton: public QLabel { Q_OBJECTpublic: HTMLButton(QWidget *parent = 0) : QLabel(parent) { setAlignment(Qt::AlignCenter); setFrameStyle(QFrame::Panel | QFrame::Raised); resize(75, 24); }protected: virtual void mousePressEvent (QMouseEvent *event) { setFrameStyle(QFrame::Panel | QFrame::Sunken); emit pressed(); } virtual void mouseReleaseEvent (QMouseEvent * event) { setFrameStyle(QFrame::Panel | QFrame::Raised); emit released(); emit clicked(); }signals: void clicked(); void pressed(); void released();};
HTMLButton *btn = new HTMLButton(this);connect(btn, SIGNAL(clicked()), this, SLOT(someslot()));
class HTMLButton: public QPushButton { Q_OBJECTpublic: HTMLButton(QWidget *parent = 0) : QPushButton(parent) { init(); } HTMLButton(const QString &text, QWidget *parent = 0) : QPushButton(text, parent) { init(); }protected: virtual void paintEvent ( QPaintEvent *event ) { QPainter painter(this); QStyleOptionButton styleOps; styleOps.initFrom(this); styleOps.state = isDown() ? QStyle::State_Sunken : QStyle::State_Raised; if (isDefault()) styleOps.features |= QStyleOptionButton::DefaultButton; style()->drawControl(QStyle::CE_PushButton, &styleOps, &painter, this); QAbstractTextDocumentLayout::PaintContext ctx; ctx.palette = palette(); doc->setHtml(text()); doc->documentLayout()->draw(&painter, ctx); }private: void init() { doc = new QTextDocument(this); }private: QTextDocument *doc;};