Reputation: 147
I have a QListWidget inside a QGraphicsScene. I add new items with QLineEdit inside. When QListWidget fills and scrollbars are active on the scroll, text does not scroll, current item representation does.
Complete code Git: code
EDIT:
I included QCheckBox inside a Horizontal layout to show why I need the setItemWidget
function.
Upvotes: 0
Views: 376
Reputation: 4484
Answer:
The text does not scroll because setItemWidget is:
void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)
Sets the widget to be displayed in the given item. This function should only be used to display static content in the place of a list widget item. If you want to display custom dynamic content or implement a custom editor widget, use QListView and subclass QItemDelegate instead.
it's nothing about QGraphicsScene
.
Solution:
If you want to make the text editable. it's much simpler then you customize the QItemDelegate
.
First, set the list widget with an edit trigger, tell the widget when to start editing.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
...
ui->listWidget->setEditTriggers(QAbstractItemView::DoubleClicked);
}
Then when you create & insert the QListWidgetItem
, make sure each item is editable.
※Replace you whole on_pushButton_clicked
function as below:
void MainWindow::on_pushButton_clicked()
{
QListWidgetItem* item = new QListWidgetItem("name");
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->listWidget->insertItem(ui->listWidget->currentRow() + 1, item);
}
Upvotes: 1