Unsolved How to create a playlist of all the files selected in the ui?
-
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
-
@kishore_hemmady Why do you call clear() after adding item?! clear() removes all items.
-
@jsulm still same problem,not able to display
-
@kishore_hemmady Sorry, but if you don't provide more code nobody will be able to tell you what is wrong...
-
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);}
-
@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.
-
hi @jsulm
actually i want to save the multiple file into the list so i used listWidget. -
@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.
-
@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. -
@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()...
-
@jsulm but when i do it for the Second time the new file is override the existing file the widget list rather forming list.
-
@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? -
@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%) -
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);