#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui
->pushButtonBack
->setIcon
(style.
standardIcon(QStyle::SP_ArrowBack));
ui
->pushButtonSend
->setIcon
(style.
standardIcon(QStyle::SP_DialogOkButton));
QPalette palbut
= ui
->pushButtonBack
->palette
();
list.append("QPushButton { font: 75 28pt \"Serif\"; border-width: 1px; border-radius: 5px; border-style: solid; border-color: "+getRGBhexColor(palbut.shadow().color())+"; "
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0.25, y2: 1, stop: 0.35 "+getRGBhexColor(palbut.light().color())+", stop: 1 "+getRGBhexColor(palbut.dark().color())+") }"
"QPushButton:pressed { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 "+getRGBhexColor(palbut.dark().color())+", stop: 1 "+getRGBhexColor(palbut.light().color())+"); }");
list.append("QPushButton { font: 75 28pt \"Serif\"; border: 1px solid "+getRGBhexColor(palyellow.shadow().color())+"; border-radius: 5px;"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.35 "+getRGBhexColor(palyellow.button().color())+", stop: 1 "+getRGBhexColor(palyellow.shadow().color())+"); min-width: 10px; }"
"QPushButton:pressed { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 "+getRGBhexColor(palyellow.dark().color())+", stop: 1 "+getRGBhexColor(palyellow.light().color())+"); }"
// "QPushButton:flat { border: none; }"
// "QPushButton:default { border-color: navy; }"
);
colorsStyleSheets.append(list);
colorsStyleSheets.append(list);
connect(&colorTimer, SIGNAL(timeout()), this, SLOT(sColorTimerTimeout()));
startColorTimer();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::startColorTimer() {
QWidget* twid
= this
->focusWidget
();
if(twid == ui->pushButtonBack)
twid->setStyleSheet(colorsStyleSheets.at(0).at(1));
else if(twid == ui->pushButtonSend)
twid->setStyleSheet(colorsStyleSheets.at(1).at(1));
colorTimer.start(1000);
}
void MainWindow::stopColorTimer() {
colorTimer.stop();
}
void MainWindow::sColorTimerTimeout() {
QWidget* twid
= this
->focusWidget
();
int idx = -1;
if(twid == ui->pushButtonBack)
tlist = colorsStyleSheets.at(0);
else if(twid == ui->pushButtonSend)
tlist = colorsStyleSheets.at(1);
if(twid == ui->pushButtonBack || twid == ui->pushButtonSend) {
tpb->setFlat(false);
idx = tlist.indexOf(twid->styleSheet());
idx++;
if(idx >= tlist.size())
idx = 0;
twid->setStyleSheet(tlist.at(idx));
}
}
qDebug("red: %x", color.red());
if(color.red() == 0)
col.append("00");
else
col.
append(QString::number(color.
red(),
16));
qDebug("green: %x", color.green());
if(color.green() == 0)
col.append("00");
else
col.
append(QString::number(color.
green(),
16));
qDebug("blue: %x", color.blue());
if(color.blue() == 0)
col.append("00");
else
col.
append(QString::number(color.
blue(),
16));
return col;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QCommonStyle style;
ui->pushButtonBack->setIcon(style.standardIcon(QStyle::SP_ArrowBack));
ui->pushButtonSend->setIcon(style.standardIcon(QStyle::SP_DialogOkButton));
QPalette palbut = ui->pushButtonBack->palette();
QPalette palyellow(QColor("yellow"));
QStringList list;
list.append("QPushButton { font: 75 28pt \"Serif\"; border-width: 1px; border-radius: 5px; border-style: solid; border-color: "+getRGBhexColor(palbut.shadow().color())+"; "
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0.25, y2: 1, stop: 0.35 "+getRGBhexColor(palbut.light().color())+", stop: 1 "+getRGBhexColor(palbut.dark().color())+") }"
"QPushButton:pressed { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 "+getRGBhexColor(palbut.dark().color())+", stop: 1 "+getRGBhexColor(palbut.light().color())+"); }");
list.append("QPushButton { font: 75 28pt \"Serif\"; border: 1px solid "+getRGBhexColor(palyellow.shadow().color())+"; border-radius: 5px;"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.35 "+getRGBhexColor(palyellow.button().color())+", stop: 1 "+getRGBhexColor(palyellow.shadow().color())+"); min-width: 10px; }"
"QPushButton:pressed { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 "+getRGBhexColor(palyellow.dark().color())+", stop: 1 "+getRGBhexColor(palyellow.light().color())+"); }"
// "QPushButton:flat { border: none; }"
// "QPushButton:default { border-color: navy; }"
);
colorsStyleSheets.append(list);
colorsStyleSheets.append(list);
connect(&colorTimer, SIGNAL(timeout()), this, SLOT(sColorTimerTimeout()));
startColorTimer();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::startColorTimer() {
QWidget* twid = this->focusWidget();
if(twid == ui->pushButtonBack)
twid->setStyleSheet(colorsStyleSheets.at(0).at(1));
else if(twid == ui->pushButtonSend)
twid->setStyleSheet(colorsStyleSheets.at(1).at(1));
colorTimer.start(1000);
}
void MainWindow::stopColorTimer() {
colorTimer.stop();
}
void MainWindow::sColorTimerTimeout() {
QWidget* twid = this->focusWidget();
QStringList tlist;
int idx = -1;
if(twid == ui->pushButtonBack)
tlist = colorsStyleSheets.at(0);
else if(twid == ui->pushButtonSend)
tlist = colorsStyleSheets.at(1);
if(twid == ui->pushButtonBack || twid == ui->pushButtonSend) {
QPushButton* tpb = qobject_cast<QPushButton*>(twid);
tpb->setFlat(false);
idx = tlist.indexOf(twid->styleSheet());
idx++;
if(idx >= tlist.size())
idx = 0;
twid->setStyleSheet(tlist.at(idx));
}
}
QString MainWindow::getRGBhexColor(const QColor color) {
QString col("#");
qDebug("red: %x", color.red());
if(color.red() == 0)
col.append("00");
else
col.append(QString::number(color.red(), 16));
qDebug("green: %x", color.green());
if(color.green() == 0)
col.append("00");
else
col.append(QString::number(color.green(), 16));
qDebug("blue: %x", color.blue());
if(color.blue() == 0)
col.append("00");
else
col.append(QString::number(color.blue(), 16));
return col;
}
To copy to clipboard, switch view to plain text mode
Bookmarks