Unsolved Why does the qlabel background in qlistwidget not display?
-
hi.
I created a custom qlistwidget.
code as follows:
QListWidgetItem * item = new QListWidgetItem(ui->listWidget); ui->listWidget->addItem(item); QLabel * lItem = new QLabel(); lItem->setAutoFillBackground(true); QPalette p = lItem->palette(); p.setBrush(QPalette::Window, QBrush(QColor(Qt::blue))); lItem->setPalette(p); ui->listWidget->setItemWidget(item, lItem); item->setSizeHint (QSize(lItem->rect().width(), lItem->rect().height()));
But its blue background does not display,why?
Thanks!
-
Hi,
Why do you need QLabels in your QListWidget ?
-
@SGaist Hi
I want to implement a button with background pictures and foreground strings.
QLabel is found to be the simplest.And QLabel implements the background fillet is also very simple.
Outside of QListWidget,It works well.
-
Then why do you need a QListWidget for ?
-
@SGaist Thank you
Listwidget is not the point of the problem.
Actually, I have many components in QListWidgetItem.
I've just chosen one of the small parts as an example.
In this QListWidgetItem part, there is a local area that uses qlabel.The qlabel also uses foreground and background features.
But the background of qlabel is invisible.
-
Well, in fact, it might be. Many people are using QListWidget has a holder for a list of widget rather than using e.g. QStyledItemDelegate to do the drawing of a special column or cell.
-
Instead of using a
QLabel
in aQListWidgetItem
just callitem ->setData(Qt::BackgroundRole,QBrush(QColor(Qt::blue));