I retrieve a file list from a folder. For each file I would like to put its date (QString) and a QLabel. For each file these three elements would be put in a QListWidget. I recover all the files and the date correctly. The problem is that these two elements are in two different items. Moreover with this method, I can not put the QLabel in the QListWidget.
Here is my code :
viewList.h :
class viewList : public QWidget{
Q_OBJECT
public:
viewList();
QString getDate();
private:
QGridLayout *gridlayout;
QHBoxLayout *hboxList;
QVBoxLayout *vboxlist;
QPushButton *button;
QLabel *myLabel;
QListWidget *listwidget;
};
viewList.cpp:
viewList::viewList(){
gridlayout=new QGridLayout;
vboxlist=new QVBoxLayout;
hboxList=new QHBoxLayout;
//Button is outside the list
button=new QPushButton("test",this);
myLabel=new QLabel("ok",this);
QString path="/home/myFolder";
listwidget=new QListWidget;
foreach(QString file, files){
listwidget->addItem(file);
listwidget->addItem(getDate());
}
vboxlist->addWidget(listwidget);
gridlayout->addWidget(button,0,0,1,1);
gridlayout->addLayout(vboxlist,1,0,1,1);
this->setLayout(gridlayout);
}
QString viewList::getDate(){
return QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
}
My three problems is that if I do listwidget-> addItem (myLabel) it does not work.In addition I would like to put the file and the label in a QHBoxLayout and the QHBoxLayout in a QVBoxLayout. But with my method I can not do it. Finally I would like QLabel, QString (date) and QString (file) to be in the same item.
Would anyone have an idea of the method for doing this? For now I just show the file and the date in two different items.
Aucun commentaire:
Enregistrer un commentaire