Add file_name for each text_edit



  • I am stuck in adding file names to each text_edits which are put in list widget . Here is the code . I don't know how to add file names at the bottom of each text_edits.I would appreciate any answers .Thanks.

    ui->listWidget->setFlow(QListView::LeftToRight);
    ui->listWidget->setMinimumSize(860,380);
    ui->listWidget->setGridSize(QSize(420, 380));
    ui->listWidget->setResizeMode(QListView::Adjust);
    ui->listWidget->setViewMode(QListView::ListMode);
    ui->listWidget->setWrapping(true);
    QDir directory = QFileDialog::getExistingDirectory(this, tr("Open      Directory"),"/home",
                                                                                                         QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks);
    
    
    
    
    directory.setNameFilters({"*.log", "*.txt" , "*.sh" , "*.yml"});
    
    for(const QFileInfo & finfo: directory.entryInfoList()){
        
        m_textEdit = new QTextEdit;
        m_textEdit -> setReadOnly(true);
        QFile data(finfo.absoluteFilePath()) ;
        data.open(QIODevice::ReadOnly);
        QTextStream stream(&data);
        QString content = stream.readAll();
        data.close();
        
        m_textEdit->setText(content);
        auto item = new QListWidgetItem("", ui->listWidget);
        m_textEdit->setMinimumSize(400,360);
        ui->listWidget->setItemWidget(item, m_textEdit);
        }


  • @Kinesis

    Add the layout to the previous example. like this:

    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    widget = new QWidget;
        auto    text = new QTextEdit(content);
        auto    label = new QLabel(finfo.fileName());
        auto    vb = new QVBoxLayout;
    
        vb->addWidget(text, 9);
        vb->addWidget(label, 1);
        widget->setLayout(vb);
        widget->setMinimumSize(100, 80);
        ui->listWidget->setItemWidget(item, widget);
    }
    


  • @Devopia53
    it works! Thanks again for your help .


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.