#include <QMainWindow>
#include <QWidget>
#include <QPushButton>
#include <QComboBox>
#include <QVBoxLayout>
{
Q_OBJECT
public:
private slots:
void blinkMe();
void blinkStyle();
void blinkPalette();
private:
};
#include <QMainWindow>
#include <QWidget>
#include <QPushButton>
#include <QComboBox>
#include <QVBoxLayout>
class Gui : public QMainWindow
{
Q_OBJECT
public:
Gui( QWidget * parent = 0 );
private slots:
void blinkMe();
void blinkStyle();
void blinkPalette();
private:
QWidget *centralwidget;
QPushButton *pushButton;
QComboBox *comboBox;
QVBoxLayout *layout;
};
To copy to clipboard, switch view to plain text mode
#include <iostream>
#include <QApplication>
#include <QString>
#include <QTimer>
#include "gui.h"
//
using namespace std;
//
int main(int argc, char ** argv)
{
Gui gui;
gui.show();
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
{
this
->setObjectName
(QString::fromUtf8("MainWindow"));
this->setWindowTitle("main window test");
centralwidget
->setObjectName
(QString::fromUtf8("centralwidget"));
this->setCentralWidget(centralwidget);
pushButton
->setObjectName
(QString::fromUtf8("pushButton"));
pushButton->setText("blink?");
pushButton->setAutoFillBackground(true);
comboBox
->setObjectName
(QString::fromUtf8("comboBox"));
comboBox->setAutoFillBackground(true);
layout->addWidget(comboBox);
layout->addWidget(pushButton);
size = size.expandedTo(this->minimumSizeHint());
this->resize(size);
connect(pushButton, SIGNAL(clicked()),
this, SLOT(blinkMe()));
}
static int blinkCount = 0;
void Gui::blinkMe()
{
cout << "trying to blink the comboBox..." << endl;;
blinkStyle();
//blinkPalette();
}
void Gui::blinkStyle()
{
if (++blinkCount > 6){
blinkCount = 0;
return;
}
if (blinkCount % 2){
//qApp->setStyleSheet("QComboBox#comboBox { background-color: yellow }");
blinkable->setStyleSheet("background-color: yellow");
}else{
//qApp->setStyleSheet("QComboBox#comboBox {}");
blinkable->setStyleSheet("");
}
blinkable->update();
QTimer::singleShot(200,
this,
SLOT(blinkStyle
()));
cout << "blink style! " << blinkable->styleSheet().toStdString() << endl;
}
void Gui::blinkPalette()
{
static QColor oldHighlightColor;
if (++blinkCount > 6){
blinkCount = 0;
return;
}
QPalette palette
= blinkable
->palette
();
if (blinkCount % 2){
oldBaseColor
= blinkable
->palette
().
color(QPalette::Base);
palette.
setColor(QPalette::Base, Qt
::yellow);
oldHighlightColor
= blinkable
->palette
().
color(QPalette::Highlight);
palette.
setColor(QPalette::Highlight, Qt
::yellow);
}else{
palette.
setColor(QPalette::Base, oldBaseColor
);
palette.
setColor(QPalette::Highlight, oldHighlightColor
);
}
blinkable->setPalette(palette);
blinkable->update();
QTimer::singleShot(200,
this,
SLOT(blinkPalette
()));
cout << "blink palette! " << endl;
}
//
#include <iostream>
#include <QApplication>
#include <QString>
#include <QTimer>
#include "gui.h"
//
using namespace std;
//
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
Gui gui;
gui.show();
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
Gui::Gui( QWidget * parent ) : QMainWindow(parent)
{
this->setObjectName(QString::fromUtf8("MainWindow"));
this->setWindowTitle("main window test");
centralwidget = new QWidget(this);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
this->setCentralWidget(centralwidget);
pushButton = new QPushButton(centralwidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setText("blink?");
pushButton->setAutoFillBackground(true);
comboBox = new QComboBox(centralwidget);
comboBox->setObjectName(QString::fromUtf8("comboBox"));
comboBox->setAutoFillBackground(true);
layout = new QVBoxLayout(centralwidget);
layout->addWidget(comboBox);
layout->addWidget(pushButton);
QSize size(322, 149);
size = size.expandedTo(this->minimumSizeHint());
this->resize(size);
connect(pushButton, SIGNAL(clicked()),
this, SLOT(blinkMe()));
}
static int blinkCount = 0;
void Gui::blinkMe()
{
cout << "trying to blink the comboBox..." << endl;;
blinkStyle();
//blinkPalette();
}
void Gui::blinkStyle()
{
if (++blinkCount > 6){
blinkCount = 0;
return;
}
QWidget* blinkable = comboBox;
if (blinkCount % 2){
//qApp->setStyleSheet("QComboBox#comboBox { background-color: yellow }");
blinkable->setStyleSheet("background-color: yellow");
}else{
//qApp->setStyleSheet("QComboBox#comboBox {}");
blinkable->setStyleSheet("");
}
blinkable->update();
QTimer::singleShot(200, this, SLOT(blinkStyle()));
cout << "blink style! " << blinkable->styleSheet().toStdString() << endl;
}
void Gui::blinkPalette()
{
static QColor oldBaseColor;
static QColor oldHighlightColor;
if (++blinkCount > 6){
blinkCount = 0;
return;
}
QWidget* blinkable = comboBox;
QPalette palette = blinkable->palette();
if (blinkCount % 2){
oldBaseColor = blinkable->palette().color(QPalette::Base);
palette.setColor(QPalette::Base, Qt::yellow);
oldHighlightColor = blinkable->palette().color(QPalette::Highlight);
palette.setColor(QPalette::Highlight, Qt::yellow);
}else{
palette.setColor(QPalette::Base, oldBaseColor);
palette.setColor(QPalette::Highlight, oldHighlightColor);
}
blinkable->setPalette(palette);
blinkable->update();
QTimer::singleShot(200, this, SLOT(blinkPalette()));
cout << "blink palette! " << endl;
}
//
To copy to clipboard, switch view to plain text mode
Bookmarks