1 Attachment(s)
QTableWidget separtion lines disappearing
Hi,
I have a perhaps somewhat unusual setup of a QTableWidget, where the tablewidget contains QLabels as cell-widgets, and those labels contain pixmaps to render something.
The problem: when I drag the columnsseparator to the left, the column separation line disappears.
I have created a simple example of the problem below. Just run it and play around with resizing the columns by dragging the header. Quickly the separation line will disappear. Screenshot:
Attachment 13001
code:
Code:
{
Q_OBJECT
public:
{
setFixedSize(500,500);
table.setColumnCount(2);
table.setRowCount(1);
table.verticalHeader()->setStretchLastSection(true);
table.
setCellWidget(0,
0, l1
= new QLabel());
table.
setCellWidget(0,
1, l2
= new QLabel());
l->addWidget(&table);
setLayout(l);
}
{
{
pm.fill(Qt::red);
l1->setPixmap(pm);
}
{
pm.fill(Qt::black);
l2->setPixmap(pm);
}
}
};
Why does this happen and how can I ensure the lines are always drawn?
Happy Holidays!
Re: QTableWidget separtion lines disappearing
Not necessarily the cause but it is usually not a good idea to override the paintEvent() method of a container.
Especially when not calling the base implementation.
If your cells really only contain a single color, my suggestion would be to set the background of the respective QTableWidgetItem instead.
http://doc.qt.io/qt-5/qtablewidgetit...#setBackground
Cheers,
_
Re: QTableWidget separtion lines disappearing
Unfortuantley the single colors were just for demonstration.
Thanks for the tip, but the paint-event-overriding is indeed no the cause here. Indeed the issue even occurs when I set the pixmaps only once.
Code:
{
//..as above, but without overriding paintEvent()
void init()
{
{
pm.fill(Qt::red);
l1->setPixmap(pm);
}
{
pm.fill(Qt::black);
l2->setPixmap(pm);
}
}
};
...
mm m;
m.show();
m.init();
...
Do you think this might be a Qt bug?
Re: QTableWidget separtion lines disappearing
Even if the pixmap is more complex, it make still sense to avoid cell widgets.
Set the pixmal as each item's DecorationRole or go for a custom delegate.
Cheers,
_