class NoEditDelegate: public QStyledItemDelegate
{
public:
NoEditDelegate
(QObject* parent
=0): QStyledItemDelegate
(parent
) {
}
{
return 0;
}
{
if (option.
state == QStyle::State_Selected || option.
state == QStyle::State_Active || option.
state == QStyle::State_Enabled || option.
state == QStyle::State_Item || option.
state == QStyle::State_HasFocus) {
QStyledItemDelegate::paint(painter, newOption, index);
return;
}
QStyledItemDelegate::paint(painter, option, index);
}
};
void MyTreeWidget
::set_items(QWidget *p
) {
__qtreewidgetitem1->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setRootIsDecorated(true);
setAllColumnsShowFocus(false);
header()->setDefaultSectionSize(100);
___qtreewidgetitem->setText(1, "Wert");
___qtreewidgetitem->setText(0, "Eigenschaft");
// here
NoEditDelegate *ne = new NoEditDelegate(this);
setSortingEnabled(false);
setItemDelegateForColumn(0, ne); // <--- here
___qtreewidgetitem1->setText(0, "Anzeige");
___qtreewidgetitem2->setText(1, "1");
___qtreewidgetitem2->setText(0, "pageno");
insertTopLevelItem(0,___qtreewidgetitem3);
___qtreewidgetitem4->setText(0, "Bearbeiten");
}
{
int pHeight = font().pointSize();
int pWidth = columnWidth(0);
p.begin(viewport());
int rc = 10;
int py = 0;
for(int i = 0; i < rc; i++)
{
p.drawRect(1,py,pWidth-2,pHeight+5);
p.drawRect(columnWidth(0)-1,py,columnWidth(1),pHeight+5);
py += pHeight+5;
}
p.end();
}
class NoEditDelegate: public QStyledItemDelegate
{
public:
NoEditDelegate(QObject* parent=0): QStyledItemDelegate(parent)
{
}
virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return 0;
}
void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
if (option.state == QStyle::State_Selected
|| option.state == QStyle::State_Active
|| option.state == QStyle::State_Enabled
|| option.state == QStyle::State_Item
|| option.state == QStyle::State_HasFocus)
{
QStyleOptionViewItem newOption(option);
newOption.palette.setBrush(QPalette::Highlight,QColor(200,100,200));
QStyledItemDelegate::paint(painter, newOption, index);
return;
}
QStyledItemDelegate::paint(painter, option, index);
}
};
void MyTreeWidget::set_items(QWidget *p)
{
QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem(this);
QTreeWidgetItem *__qtreewidgetitem1 = new QTreeWidgetItem(__qtreewidgetitem);
__qtreewidgetitem1->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setRootIsDecorated(true);
setAllColumnsShowFocus(false);
header()->setDefaultSectionSize(100);
QTreeWidgetItem *___qtreewidgetitem = headerItem();
___qtreewidgetitem->setText(1, "Wert");
___qtreewidgetitem->setText(0, "Eigenschaft");
// here
NoEditDelegate *ne = new NoEditDelegate(this);
setSortingEnabled(false);
setItemDelegateForColumn(0, ne); // <--- here
QTreeWidgetItem *___qtreewidgetitem1 = topLevelItem(0);
___qtreewidgetitem1->setText(0, "Anzeige");
QTreeWidgetItem *___qtreewidgetitem2 = ___qtreewidgetitem1->child(0);
___qtreewidgetitem2->setText(1, "1");
___qtreewidgetitem2->setText(0, "pageno");
QTreeWidgetItem *___qtreewidgetitem3 = new QTreeWidgetItem(this);
insertTopLevelItem(0,___qtreewidgetitem3);
QTreeWidgetItem *___qtreewidgetitem4 = topLevelItem(1);
___qtreewidgetitem4->setText(0, "Bearbeiten");
}
void MyTreeWidget::paintEvent(QPaintEvent *event)
{
QTreeWidget::paintEvent(event);
int pHeight = font().pointSize();
int pWidth = columnWidth(0);
QPainter p;
p.begin(viewport());
int rc = 10;
int py = 0;
for(int i = 0; i < rc; i++)
{
p.drawRect(1,py,pWidth-2,pHeight+5);
p.drawRect(columnWidth(0)-1,py,columnWidth(1),pHeight+5);
py += pHeight+5;
}
p.end();
}
To copy to clipboard, switch view to plain text mode
Bookmarks