@@ -322,19 +322,22 @@ void SignalItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
322
322
323
323
// color label
324
324
auto bg_color = getColor (item->sig );
325
- QRect rc{option.rect .left (), option.rect .top (), color_label_width, option.rect .height ()};
325
+ int h_margin = option.widget ->style ()->pixelMetric (QStyle::PM_FocusFrameHMargin) + 1 ;
326
+ int v_margin = option.widget ->style ()->pixelMetric (QStyle::PM_FocusFrameVMargin);
327
+ QRect rc{option.rect .left () + h_margin, option.rect .top (), color_label_width, option.rect .height ()};
326
328
painter->setPen (Qt::NoPen);
327
329
painter->setBrush (item->highlight ? bg_color.darker (125 ) : bg_color);
328
- painter->drawRoundedRect (rc.adjusted (0 , 2 , 0 , -2 ), 3 , 3 );
330
+ painter->drawRoundedRect (rc.adjusted (0 , v_margin , 0 , -v_margin ), 3 , 3 );
329
331
painter->setPen (item->highlight ? Qt::white : Qt::black);
330
332
painter->setFont (small_font);
331
333
painter->drawText (rc, Qt::AlignCenter, QString::number (item->row () + 1 ));
332
334
333
335
// signal name
334
336
painter->setFont (option.font );
335
- painter->setPen ((option.state & QStyle::State_Selected ? option. palette . highlightedText () : option. palette . text ()). color ( ));
337
+ painter->setPen (option. palette . color (option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text ));
336
338
QString text = index .data (Qt::DisplayRole).toString ();
337
- QRect text_rect = option.rect .adjusted (rc.width () + 6 , 0 , 0 , 0 );
339
+ QRect text_rect = option.rect ;
340
+ text_rect.setLeft (rc.right () + h_margin * 2 );
338
341
text = painter->fontMetrics ().elidedText (text, Qt::ElideRight, text_rect.width ());
339
342
painter->drawText (text_rect, option.displayAlignment , text);
340
343
painter->restore ();
@@ -343,7 +346,7 @@ void SignalItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
343
346
if (option.state & QStyle::State_Selected) {
344
347
painter->fillRect (option.rect , option.palette .highlight ());
345
348
}
346
- painter->setPen ((option.state & QStyle::State_Selected ? option. palette . highlightedText () : option. palette . text ()). color ( ));
349
+ painter->setPen (option. palette . color (option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text ));
347
350
QRect rc = option.rect .adjusted (0 , 0 , -70 , 0 );
348
351
auto text = painter->fontMetrics ().elidedText (index .data (Qt::DisplayRole).toString (), Qt::ElideRight, rc.width ());
349
352
painter->drawText (rc, Qt::AlignRight | Qt::AlignVCenter, text);
@@ -442,8 +445,11 @@ void SignalView::rowsChanged() {
442
445
if (!tree->indexWidget (index )) {
443
446
QWidget *w = new QWidget (this );
444
447
QHBoxLayout *h = new QHBoxLayout (w);
445
- h->setContentsMargins (0 , 2 , 0 , 2 );
446
- h->addStretch (1 );
448
+ int v_margin = style ()->pixelMetric (QStyle::PM_FocusFrameVMargin);
449
+ int h_margin = style ()->pixelMetric (QStyle::PM_FocusFrameHMargin);
450
+ h->setContentsMargins (0 , v_margin, -h_margin, v_margin);
451
+ h->setSpacing (style ()->pixelMetric (QStyle::PM_ToolBarItemSpacing));
452
+ h->addStretch (0 );
447
453
448
454
auto remove_btn = toolButton (" x" , tr (" Remove signal" ));
449
455
auto plot_btn = toolButton (" graph-up" , " " );
0 commit comments