Hi,
I want to change (1) background color for a QPushbutton (2) color of text for QPushbutton (3) background color of Qlabel (4) color of text for QLabel. I have been looking at other threads but have not been able to figure out how to best do this.
I am posting a simple helloworld example for it. Can anyone please guide me how to modify it to do the above things?
Thanks in advance.
Regards,
Ashish
#include <QApplication>
#include <QPushButton>
#include <QColorGroup>
#include <QLabel>
#include <QWidget>
#include <QHBoxLayout>
#include <QObject>
int main(int argc, char *argv[])
{
window->setWindowTitle("my test window");
hello->setText("Hello world!");
hello
->setFont
(QFont("Comic Sans MS",
30,
QFont::Bold));
//pal->setColor(QPalette(QColor(250,0,0)));
//pal->setColor(QPalette(?????-
//hello->setPalette(QPalette(Qt::red));
mylabel->setText("This is my Label");
myl->addWidget(hello);
myl->addWidget(mylabel);
window->setLayout(myl);
//mylabel->show();
//hello->show();
window->show();
return app.exec();
}
#include <QApplication>
#include <QPushButton>
#include <QColorGroup>
#include <QLabel>
#include <QWidget>
#include <QHBoxLayout>
#include <QObject>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window=new QWidget();;
QHBoxLayout *myl= new QHBoxLayout();
window->setWindowTitle("my test window");
QPushButton *hello=new QPushButton();
hello->setText("Hello world!");
hello->setFont(QFont("Comic Sans MS",30,QFont::Bold));
QPalette *pal= new QPalette(hello->palette());
//pal->setColor(QPalette(QColor(250,0,0)));
//pal->setColor(QPalette(?????-
//hello->setPalette(QPalette(Qt::red));
QLabel *mylabel=new QLabel();
mylabel->setFont(QFont("Times",20,QFont::Bold));
mylabel->setPalette(QPalette(Qt::red));
mylabel->setText("This is my Label");
myl->addWidget(hello);
myl->addWidget(mylabel);
window->setLayout(myl);
//mylabel->show();
//hello->show();
window->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks