#include <QtGui>
static void setToolBoxButtonColor
(QToolBox* toolBox,
int index,
QColor color
) {
int i = 0;
foreach
(QAbstractButton* button, toolBox
->findChildren<QAbstractButton
*>
()) {
// make sure only toolbox button palettes are modified
if (button
->metaObject
()->className
() == QString("QToolBoxButton")) {
if (i == index)
{
// found correct button
button->setPalette(p);
break;
}
i++;
}
}
}
int main(int argc, char *argv[])
{
toolBox
->addItem
(new QLineEdit("HAHA"),
"LineEdit");
toolBox
->addItem
(new QTextEdit("HOHO"),
"TextEdit");
toolBox
->addItem
(new QLabel("MUAHAHA"),
"Label");
setToolBoxButtonColor(toolBox, 0, Qt::red);
setToolBoxButtonColor(toolBox, 1, Qt::green);
setToolBoxButtonColor(toolBox, 2, Qt::blue);
toolBox->show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
#include <QtGui>
static void setToolBoxButtonColor(QToolBox* toolBox, int index, QColor color)
{
int i = 0;
foreach (QAbstractButton* button, toolBox->findChildren<QAbstractButton*>())
{
// make sure only toolbox button palettes are modified
if (button->metaObject()->className() == QString("QToolBoxButton"))
{
if (i == index)
{
// found correct button
QPalette p = button->palette();
p.setColor(QPalette::Button, color);
button->setPalette(p);
break;
}
i++;
}
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QToolBox* toolBox = new QToolBox;
toolBox->addItem(new QLineEdit("HAHA"), "LineEdit");
toolBox->addItem(new QTextEdit("HOHO"), "TextEdit");
toolBox->addItem(new QLabel("MUAHAHA"), "Label");
setToolBoxButtonColor(toolBox, 0, Qt::red);
setToolBoxButtonColor(toolBox, 1, Qt::green);
setToolBoxButtonColor(toolBox, 2, Qt::blue);
toolBox->show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks