/*------------------------------------------------------------------+
| Custom paint event to draw alternate row colours. |
+------------------------------------------------------------------*/
painter.setPen(Qt::NoPen);
// Fill the entire background with even colour first, then draw odd
// rectangles. Probably more efficient this way
painter.setBrush(evenRowColourProperty);
painter.drawRect(0, 0, this->width(), this->height());
// This could be more... elegant
int y = margin - (spacing / 2);
bool alt = false;
painter.setBrush(oddRowColourProperty);
for (int i = 0; i < formLayout->rowCount(); i++) {
QLayoutItem* item
= formLayout
->itemAt
(i, QFormLayout
::FieldRole);
if (item) {
int h = item->sizeHint().height() + spacing;
if (alt) {
painter.drawRect(0, y, this->width(), h);
}
y += h;
alt = !alt;
}
else {
item = formLayout->itemAt(i, QFormLayout::SpanningRole);
if (item) {
int h = item->sizeHint().height() + spacing;
if (alt) {
painter.drawRect(0, y, this->width(), h);
}
y += h;
alt = !alt;
}
}
}
}
/*------------------------------------------------------------------+
| Custom paint event to draw alternate row colours. |
+------------------------------------------------------------------*/
void AbstractPropertyPage::paintEvent(QPaintEvent*) {
QPainter painter(this);
painter.setPen(Qt::NoPen);
// Fill the entire background with even colour first, then draw odd
// rectangles. Probably more efficient this way
painter.setBrush(evenRowColourProperty);
painter.drawRect(0, 0, this->width(), this->height());
// This could be more... elegant
int y = margin - (spacing / 2);
bool alt = false;
painter.setBrush(oddRowColourProperty);
for (int i = 0; i < formLayout->rowCount(); i++) {
QLayoutItem* item = formLayout->itemAt(i, QFormLayout::FieldRole);
if (item) {
int h = item->sizeHint().height() + spacing;
if (alt) {
painter.drawRect(0, y, this->width(), h);
}
y += h;
alt = !alt;
}
else {
item = formLayout->itemAt(i, QFormLayout::SpanningRole);
if (item) {
int h = item->sizeHint().height() + spacing;
if (alt) {
painter.drawRect(0, y, this->width(), h);
}
y += h;
alt = !alt;
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks