From QListWidget to QTableWidget



  • Hello, I've made a playlist in QListWidget and works fine... But I can't add additional columns to QListWidget so I have to use QTableWidget instead... I tried everything and just can't make it work...

    Here is my code for QListWidget... I tried to do same way for QTableWidget but gives me error "Can't convert QString to QListWidgetItem"... What I am doing wrong???

    @void MainWindow::on_Playlist_clicked()
    {
    directory = QFileDialog::getExistingDirectory(this,tr("Select directory for files to import"),"C:/Users/Admin/Desktop/Narodni");
    if(directory.isEmpty())
    return;
    QDir dir(directory);
    files = dir.entryList(QStringList() << "*.mp3",QDir::Files);
    for(const QString& f:files)
    {
    content.push_back(QUrl::fromLocalFile(dir.path()+"/" + f));
    QFileInfo fi(f);
    ui->listWidget1->addItem(fi.fileName());

    }
    ui->listWidget1->setCurrentRow(playlist->currentIndex() != -1? playlist->currentIndex():0);
    playlist->addMedia(content);
    

    }@


  • Lifetime Qt Champion

    Hi,

    Are you saying that you are having an error concerning QListWidget when using a QTableWidget ?



  • No. I want to change QListWidget with QTableWidget. Remove QListWidget and add QTableWidget instead. But QTableWidget can't read QString directory.

    I want to get this
    !http://img31.imageshack.us/img31/4480/wzc5.png(C)!

    Right now I have this
    !http://img546.imageshack.us/img546/6900/dpyt.png(A)!

    I can add playlist to my listwidget (code is above), but I don't know how to add it to tablewidget...


  • Lifetime Qt Champion

    It's not that it can't read strings, it doesn't work the same way as QListWidget. You need to create a QTableWidgetItem for each string and set it in the right cell



  • Well ye that is a problem... I can't save data to QTableWidgetItem cus it gives me some error
    list is QTableWidgetItem...
    @ item = QFileDialog::getExistingDirectory(this,tr("Select directory for files to import"),"C:/Users/Admin/Desktop/Narodni");@

    QFileDialog does not accept QTableWidgetItem but only QString...

    Do you have skype or facebook where I can contact you??? This is a school project that I have to do till February and I would need a bit more help...


  • Lifetime Qt Champion

    Please read the documentation, QTableWidgetItem has a text() method


Log in to reply
 

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