Key press event to choose list
-
@Kinesis Can't you just use http://doc.qt.io/qt-5/qlistwidget.html#currentRowChanged ?
-
@jsulm
Well , as you said I tried to use currentRow Changed , but I need to take the text from current row , to get directory path. How can I get the text from current row.There may be some mistakes in my code.Take a look please.connect(listWidget_dirList, & QListWidget::currentRowChanged,[directory,listWidget_main,this](int currentRow) { listWidget_main->show(); listWidget_main->clear(); // QDir directory(item->text()); QDir dir = directory.absolutePath() + '/' + currentRow->text(); dir.setNameFilters({"*.png", "*.jpg"}); for(const QFileInfo & finfo: dir.entryInfoList()){ ---------------- ---------------- ---------------- } });
-
@Kinesis As you can see currentRow is an integer - you can't call any methods on it, right?
If you check the documentation you will find this: http://doc.qt.io/qt-5/qlistwidget.html#item -
@Kinesis I already suggested what to do to get the text. Did you read it? Again: you can get the current item using currentRow and http://doc.qt.io/qt-5/qlistwidget.html#item, then you simply call http://doc.qt.io/qt-5/qlistwidgetitem.html#text on the item to get the text.
-
Hi,
@Kinesis said in Key press event to choose list:
listWidget_main->show();
listWidget_main->clear();Aren't you emptying the content of your listWidget before getting the value you are interested in ?
-
@Kinesis said in Key press event to choose list:
QListWidgetItem *item(int row)
connect(listWidget_dirList, & QListWidget::currentRowChanged,[directory,listWidget_main,this](int currentRow) { listWidget_main->show(); listWidget_main->clear(); QListWidgetItem *item = listWidget_dirList->item(currentRow); if (item) { QString text = item->text(); ... }
-
My bad, I misread from where the signal came from.