I have a QListWidget which has items in it that can be edited(its a to do list), every item has the value Qt::ItemIsEditable which allows me to double click to edit the text value, however when i do this the textbox turns to black, i want to change the background color from black to something else, does anyone know how to do that?
Here is the code that creates all the items in the list
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),
ui(new Ui::MainWindow)
{ ui->setupUi(this);
QFile file(path);
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", file.errorString());
}
QTextStream in(&file);
while(!in.atEnd()) {
QListWidgetItem *item = new QListWidgetItem(in.readLine(), ui->listWidget);
if(item->checkState())
{
item->setCheckState(Qt::Checked);
}
else
{
item->setCheckState(Qt::Unchecked);
}
item->setForeground(QBrush(Qt::black));
ui->listWidget->addItem(item);
item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsUserCheckable);
}
file.close();
}
Im also using QSS stylesheet:
QListWidget::indicator:checked {
image: url(:/resources/images/sillycat.jpg);
}
QListWidget::item:selected {
background-color: #9de0be;
color: black;
}
QListWidget::item:editable {
background-color: white;
}
Try this:
ui->listWidget->setStyleSheet("QListView QLineEdit{background:green}");;