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);
}