Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. From QListWidget to QTableWidget

From QListWidget to QTableWidget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

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

    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            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...

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved