Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C++ by registered user raphael ( 1 year ago )
#ifndef PUSHBUTTONROUGE_H
#define PUSHBUTTONROUGE_H

#include <QPushButton>

class PushButtonRouge : public QPushButton
{
public:
    PushButtonRouge(QWidget *parent);
protected:
    void paintEvent(QPaintEvent *event) override;
};

#endif // PUSHBUTTONROUGE_H
//---------------------------------------------------------------------------
#include "pushbuttonrouge.h"
#include <QPainter>
#include <QPaintEvent>
#include <QStyleOptionButton>

PushButtonRouge::PushButtonRouge(QWidget *parent) : QPushButton(parent)
{

}

void PushButtonRouge::paintEvent(QPaintEvent *event)
{
    QStyleOptionButton option;
    option.initFrom(this);
    option.text = text();

    QPainter painter(this);

    if (option.state & QStyle::State_MouseOver) {
        //Si le bouton est survolé
        painter.fillRect(event->rect(), Qt::lightGray);
    } else if (option.state & QStyle::State_Sunken) {
        //Si le bouton est enfoncé
        painter.fillRect(event->rect(), Qt::darkRed);
    } else {
        //État normal
        painter.fillRect(event->rect(), Qt::red);
    }

    painter.setPen(Qt::green);
    painter.drawText(rect(), Qt::AlignCenter, option.text);
}

//-------------------------------------------------------------------------------------------------
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setStyleSheet("background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 blue, stop:0.5 white, stop:1 red);");

}

MainWindow::~MainWindow()
{
    delete ui;
}

 

Revise this Paste

Parent: 126238
Children: 126240
Your Name: Code Language: