#include <QtGui>
{
protected:
{
// draw "something" on parent widget with the same color
p.
fillRect(rect
(),
QColor(140,
134,
115));
}
};
class ColorLabel
: public QLabel{
public:
ColorLabel
(const QString
& text,
QWidget* parent
= 0) {
// a label with background palette..
setAlignment(Qt::AlignCenter);
p.
setColor(backgroundRole
(),
QColor(140,
134,
115));
setPalette(p);
setAutoFillBackground(true);
// a frame just to indicate where are the boundaries of the label
}
};
int main(int argc, char *argv[])
{
ColorDialog* dialog = new ColorDialog;
ColorLabel* label = new ColorLabel("test");
lay->addWidget(label);
dialog->setLayout(lay);
dialog->show();
return a.exec();
}
#include <QtGui>
class ColorDialog: public QDialog
{
protected:
void paintEvent(QPaintEvent* event)
{
// draw "something" on parent widget with the same color
QDialog::paintEvent(event);
QPainter p(this);
p.fillRect(rect(), QColor(140,134,115));
}
};
class ColorLabel: public QLabel
{
public:
ColorLabel(const QString& text, QWidget* parent = 0)
: QLabel(text, parent)
{
// a label with background palette..
setAlignment(Qt::AlignCenter);
QPalette p = palette();
p.setColor(backgroundRole(), QColor(140,134,115));
setPalette(p);
setAutoFillBackground(true);
// a frame just to indicate where are the boundaries of the label
setFrameStyle(QFrame::Box);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ColorDialog* dialog = new ColorDialog;
ColorLabel* label = new ColorLabel("test");
QVBoxLayout* lay = new QVBoxLayout;
lay->addWidget(label);
dialog->setLayout(lay);
dialog->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
If you mean something different, please supply a minimal compilable example to test.
Bookmarks