Transparency in Table/Tree View/WIdget with setAlternatingRowColors and Delegate
-
@mrjj
My editer is a Qwigdet with a layout on it and inside the layout there are other widgets.
I have not reimplemented any painting for it, so it just uses the default paint routines.The paint from the delegate is this:
void TreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,const QModelIndex &index) const { QWidget* editor = nullptr; editor = new DummyDelegate(); QStyleOptionViewItem option_widget = option; QStyledItemDelegate::initStyleOption(&option_widget, index); painter->save(); painter->setClipRect(option.rect); editor->setPalette(option_widget.palette); editor->resize(option_widget.rect.size()); painter->translate(option_widget.rect.topLeft()); editor->render(painter, QPoint(), QRegion(), QWidget::DrawChildren); painter->restore(); delete editor; }
What also maybe could cause the problem is, that the TreeView I'm am using has a frozen column, like in the FrozenTableView example. Really hard to isolate the source of the problem. I guess I'll have to try to recreate it on a minimal example.
EDIT: nope, that wasn't involved. Still there without frozen columns -
Hi
I think its the editor as that would also explain
QWidget {
color: #000000;
background: #f0f0f0;
}so to test that please
do
editor->resize(option_widget.rect.size());
editor->resize(QRect(0,0,50,50);and if that grey thing then is small, then you know why.
-
Thanks for the further hint. I've tried that, the grey header is smaller now, but it still may overlap.
What I've also noticed is, that the Text seems to be renderd twice with a small ofset somehow when it is overlapping.
Also with the text when i do not clip to rect the overlap is gone.
-
@mrjj
Ok :) so but what could be the reason? Or do you have any ideas for fixing it?EDIT: I've also tested some "compact mode" where i can remove the header from the cells, and the view will be shown without the cell headers.
When I switch to compact mode the artefacts stay there for a while and only dissapear after a few clicks or something.
So at that moment the editors arent even there any more. Could this be a timing problem maybe? -
Dummy Delegate is just a normal widget with layouts on it that hold other widgets
DummyDelegat::DummyDelegat(QWidget *parent): QWidget(parent), m_compact_mode(false) { m_main_layout = new QVBoxLayout(); m_main_layout->setSpacing(2); m_main_layout->setContentsMargins(0, 0, 0, 0); m_main_layout->setAlignment(Qt::AlignTop); this->setLayout(m_main_layout); m_header = new QWidget(this); m_header->setFixedHeight(12); m_main_layout->addWidget(m_header); m_header_layout = new QHBoxLayout(); m_header_layout->setContentsMargins(5, 0, 0, 0); m_header_layout->setSpacing(2); m_header->setLayout(m_header_layout); m_header_icon_label = new QLabel(this); m_header_icon_label->setFixedHeight(12); m_header_icon_label->setFixedWidth(12); m_header_layout->addWidget(m_header_icon_label); m_header_label = new QLabel(this); m_header_layout->addWidget(m_header_label); }
-
@gde23
Ok. I have no idea then
as its clearly the grey we see.I wonder one thing
You don't give it a parent when you new it -
so how do you avoid it having borders etc like a Window normally have?editor = new DummyDelegate( NO PARENT );
Also you could try to give it a parent to see if that keeps it inside
-
@mrjj Yeah :) I finally got it working with your help.
The trick is to first add the View as a parent for the DelgateEditor.
Now we still get the overlap. However now when you remove painter->setClipRect(option.rect); from paint() is does not paint into neighboring cells any more, so you do not need that line of code anymore and without that line of code the problem is gone :)Thanks again for all the help, I never would have come up with that idea. (And I still don't get why it did not work in the first place)