Add textEdits on listWidget
Solved
General and Desktop
-
@Kinesis If the text is read-only why not simply add it using http://doc.qt.io/qt-5/qlistwidgetitem.html#QListWidgetItem-2 ?
QListWidgetItem *item = new QListWidgetItem(icon, "some text"); listWidget->addItem(item);
-
@jsulm
read-only text means text inside textedit is read only.plz take alook my code and u will understand clearly.for(const QFileInfo & finfo: directory.entryInfoList()){ m_textEdit = new QTextEdit; QFile data(finfo.absoluteFilePath()) ; data.open(QIODevice::ReadOnly); QTextStream stream(&data); QString content = stream.readAll(); data.close(); m_textEdit->setText(content); m_textEdit->show(); ui->listWidget->addItem(m_textEdit); }
The problem is that I cant add textEdit on listWidget easily .
-
@Kinesis Sorry, but I still don't get why you need a QTextEdit? QListWidgetItem already can show text:
for(const QFileInfo & finfo: directory.entryInfoList()){ QFile data(finfo.absoluteFilePath()) ; data.open(QIODevice::ReadOnly); QTextStream stream(&data); QString content = stream.readAll(); data.close(); QListWidgetItem *m_textEdit = new QListWidgetItem(content); ui->listWidget->addItem(m_textEdit); }
-
@Kinesis My question was whether you want to show it in a WINDOW like in your picture.
And can you explain why you need a QTextEdit to show read-only text if you already can show text in QListWidget? I really don't understand that. -
like this(only example):
ui->listWidget->setFlow(QListView::LeftToRight); ui->listWidget->setGridSize(QSize(110, 90)); ui->listWidget->setResizeMode(QListView::Adjust); ui->listWidget->setViewMode(QListView::ListMode); ui->listWidget->setWrapping(true); for (const QFileInfo &finfo : directory.entryInfoList()) { [...] auto item = new QListWidgetItem("", ui->listWidget); auto text = new QTextEdit(content); text->setMinimumSize(100, 80); ui->listWidget->setItemWidget(item, text); }