#include <QtGui>
// NOTE: you may use the ProxyStyle is available at Qt Centre wiki but make it inherit QCommonStyle instead of QStyle
#include "proxystyle.h"
class MyProxyStyle : public ProxyStyle
{
public:
explicit MyProxyStyle(const QString& baseStyle) : ProxyStyle(baseStyle)
{
}
{
if (element
== QStyle::PE_IndicatorBranch) {
painter->save();
painter
->setPen
(QPen(Qt
::blue,
1, Qt
::DashLine));
QCommonStyle::drawPrimitive(element, option, painter, widget
);
painter->restore();
}
ProxyStyle::drawPrimitive(element, option, painter, widget);
}
};
int main(int argc, char* argv[])
{
tree.setStyle(new MyProxyStyle(app.style()->objectName()));
for (int i = 0; i < 10; ++i)
tree.show();
return app.exec();
}
#include <QtGui>
// NOTE: you may use the ProxyStyle is available at Qt Centre wiki but make it inherit QCommonStyle instead of QStyle
#include "proxystyle.h"
class MyProxyStyle : public ProxyStyle
{
public:
explicit MyProxyStyle(const QString& baseStyle) : ProxyStyle(baseStyle)
{
}
void drawPrimitive(PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0) const
{
if (element == QStyle::PE_IndicatorBranch)
{
painter->save();
painter->setPen(QPen(Qt::blue, 1, Qt::DashLine));
QCommonStyle::drawPrimitive(element, option, painter, widget);
painter->restore();
}
ProxyStyle::drawPrimitive(element, option, painter, widget);
}
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QTreeWidget tree;
tree.setStyle(new MyProxyStyle(app.style()->objectName()));
for (int i = 0; i < 10; ++i)
new QTreeWidgetItem(&tree, QStringList() << QString::number(i));
tree.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks