Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to create a playlist of all the files selected in the ui?
Forum Updated to NodeBB v4.3 + New Features

How to create a playlist of all the files selected in the ui?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
19 Posts 3 Posters 4.9k 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.
  • K kishore_hemmady

    I have a browse button in the ui for selecting files.All the selected files should come in a scrollarea with both horizontal scroll bar and vertical scrollbar showing the names of the files selected.Please suggest

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @kishore_hemmady What about http://doc.qt.io/qt-5/qlistwidget.html?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • K Offline
      K Offline
      kishore_hemmady
      wrote on last edited by
      #3

      hi @jsulm

      I have added these snippet in my code for listing the files and for displaying it

       QListWidgetItem *newItem = new QListWidgetItem;
      newItem->setText(itemText);
      listWidget->insertItem(row, newItem);
      

      but the saved files are not displaying in UI .
      what changes i have to do so that the the list of files are visible in the UI .

      jsulmJ 1 Reply Last reply
      0
      • K kishore_hemmady

        hi @jsulm

        I have added these snippet in my code for listing the files and for displaying it

         QListWidgetItem *newItem = new QListWidgetItem;
        newItem->setText(itemText);
        listWidget->insertItem(row, newItem);
        

        but the saved files are not displaying in UI .
        what changes i have to do so that the the list of files are visible in the UI .

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @kishore_hemmady That should work. Can you show more code? From where do you get itemText? Is the code above really executed?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kishore_hemmady
          wrote on last edited by
          #5

          itemText is Qstring variable which stores the path of the file,

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kishore_hemmady
            wrote on last edited by
            #6

            hi @jsulm

            I am able to store it in a list but not able to show the list in Ui ,I am using listWidget in UI.

              ui->listWidget->addItem(newItem);
              ui->listWidget->clear();
            

            i am not able to show the list using these 2 lines of code

            jsulmJ 1 Reply Last reply
            0
            • K kishore_hemmady

              hi @jsulm

              I am able to store it in a list but not able to show the list in Ui ,I am using listWidget in UI.

                ui->listWidget->addItem(newItem);
                ui->listWidget->clear();
              

              i am not able to show the list using these 2 lines of code

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @kishore_hemmady Why do you call clear() after adding item?! clear() removes all items.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • K Offline
                K Offline
                kishore_hemmady
                wrote on last edited by
                #8

                @jsulm still same problem,not able to display

                jsulmJ 1 Reply Last reply
                0
                • K kishore_hemmady

                  @jsulm still same problem,not able to display

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @kishore_hemmady Sorry, but if you don't provide more code nobody will be able to tell you what is wrong...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kishore_hemmady
                    wrote on last edited by
                    #10

                    HI @jsulm

                    these are the 2 methods to do this

                    QString fileNameForZOne;
                    fileNameForZOne = QFileDialog::getOpenFileName( );
                    where fileNameForZOne variable which stores the filepath.

                    void MainWindow::on_addFile_clicked()
                    {
                    QLineEdit *l[10];
                    int row=1;
                    for(int r=0;r<10;r++){
                    l[r] = new QLineEdit(fileNameForZOne);
                    ui->scrollArea->setWidget(l[r]);
                    // ui->scrollArea->addScrollBarWidget(l[r],Qt::AlignLeft);

                    }
                    /=======================================================/

                    QListWidget *listWidget = new QListWidget(this);
                    QListWidgetItem *newItem = new QListWidgetItem;
                    newItem->setText(fileNameForZOne);
                    listWidget->insertItem(row, newItem);
                    ui->listWidget->addItem(newItem);

                    }

                    jsulmJ 1 Reply Last reply
                    0
                    • K kishore_hemmady

                      HI @jsulm

                      these are the 2 methods to do this

                      QString fileNameForZOne;
                      fileNameForZOne = QFileDialog::getOpenFileName( );
                      where fileNameForZOne variable which stores the filepath.

                      void MainWindow::on_addFile_clicked()
                      {
                      QLineEdit *l[10];
                      int row=1;
                      for(int r=0;r<10;r++){
                      l[r] = new QLineEdit(fileNameForZOne);
                      ui->scrollArea->setWidget(l[r]);
                      // ui->scrollArea->addScrollBarWidget(l[r],Qt::AlignLeft);

                      }
                      /=======================================================/

                      QListWidget *listWidget = new QListWidget(this);
                      QListWidgetItem *newItem = new QListWidgetItem;
                      newItem->setText(fileNameForZOne);
                      listWidget->insertItem(row, newItem);
                      ui->listWidget->addItem(newItem);

                      }

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @kishore_hemmady Did you try to debug on_addFile_clicked() step-by-step to see what happens?
                      Why do you have this line:

                      QListWidget *listWidget = new QListWidget(this);
                      

                      listWidget isn't used.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kishore_hemmady
                        wrote on last edited by
                        #12

                        hi @jsulm
                        actually i want to save the multiple file into the list so i used listWidget.

                        jsulmJ 1 Reply Last reply
                        0
                        • K kishore_hemmady

                          hi @jsulm
                          actually i want to save the multiple file into the list so i used listWidget.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by jsulm
                          #13

                          @kishore_hemmady Again, you don't use listWidget. You add your items to ui->listWidget, listWidget isn't shown anywhere. If you really want to use it you should call

                          listWidget->show();
                          

                          But why do you need it? You already have ui->listWidget to which you add the items.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • K Offline
                            K Offline
                            kishore_hemmady
                            wrote on last edited by
                            #14

                            @jsulm ,
                            i am adding it to listWidget but not able to display the added file into the listwidget in UI,
                            so i took list widget in UI to show the list of selected files.
                            problem here is not able to show the files selected inside a list widget.

                            jsulmJ 1 Reply Last reply
                            0
                            • K kishore_hemmady

                              @jsulm ,
                              i am adding it to listWidget but not able to display the added file into the listwidget in UI,
                              so i took list widget in UI to show the list of selected files.
                              problem here is not able to show the files selected inside a list widget.

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              @kishore_hemmady I will try to explain once more:

                              QListWidget *listWidget = new QListWidget(this); // Here you create a new QListWidget
                              QListWidgetItem *newItem = new QListWidgetItem;
                              newItem->setText(fileNameForZOne);
                              listWidget->insertItem(row, newItem); // Here you add items to this new QListWidget
                              ui->listWidget->addItem(newItem);
                              

                              You NEVER call listWidget->show(); so it is NEVER shown in the UI! Why do you have it then? Either remove it or call listWidget->show()...

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              1
                              • K Offline
                                K Offline
                                kishore_hemmady
                                wrote on last edited by
                                #16

                                @jsulm but when i do it for the Second time the new file is override the existing file the widget list rather forming list.

                                jsulmJ 1 Reply Last reply
                                0
                                • K kishore_hemmady

                                  @jsulm but when i do it for the Second time the new file is override the existing file the widget list rather forming list.

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #17

                                  @kishore_hemmady If you use addItem() it should not override anything but append at the end, see http://doc.qt.io/qt-5/qlistwidget.html#addItem-1
                                  Do you call clear() somewhere?

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  1
                                  • K Offline
                                    K Offline
                                    kishore_hemmady
                                    wrote on last edited by kishore_hemmady
                                    #18

                                    @jsulm thank you,
                                    I am successfully added the file into list widget.
                                    now i am trying to delete the files from the list which is selected.
                                    for this I should have a checkbox for every file selected.
                                    how can i delete the file name upon clicking remove button.
                                    ![0_1520664120615_Screenshot from 2018-03-08 17-41-05.png](Uploading 100%)

                                    M 1 Reply Last reply
                                    0
                                    • K kishore_hemmady

                                      @jsulm thank you,
                                      I am successfully added the file into list widget.
                                      now i am trying to delete the files from the list which is selected.
                                      for this I should have a checkbox for every file selected.
                                      how can i delete the file name upon clicking remove button.
                                      ![0_1520664120615_Screenshot from 2018-03-08 17-41-05.png](Uploading 100%)

                                      M Offline
                                      M Offline
                                      mvuori
                                      wrote on last edited by
                                      #19

                                      You have two unrelated questions here. First, how to get the items that have been checked? Just scan the listItems to see which ones have isSelected() true. Then you can do whatever you wish with those items.

                                      Second, how to use a checkbox. When you googled about it with "qlistwidget checkboxes", I'm sure you found that you need to set the items' flags & state as in
                                      item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
                                      item->setCheckState(Qt::Unchecked);

                                      1 Reply Last reply
                                      1

                                      • Login

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