Can we create labels based on data automatically
-
wrote on 29 Feb 2020, 13:32 last edited by
Hi ,
I am recieving udp packets and displaying in qt,Now i am trying to display data in labels, like based on packets automatically labels should create and data should display on labels .Is it possible to do like that any help. -
You really don't want to create a label per udp packet. Take a look at the itemviews.
-
Hi
Yes you can create QLables dynamically but it gets heavy fast so as Christian-Ehrlicher says,
a model and a ListView is much more fun.
You could try out with a QStringListModel if you dont plan to show millions of rows.You can see here how to use one.
https://www.bogotobogo.com/Qt/Qt5_QListView_QStringListModel_ModelView_MVC.phpit shows how to add new and remove from the model.
Basically you can place a QListView on the UI form and do
// Create model model = new QStringListModel(this); // its a member // Make data QStringList List; List << "Clair de Lune" << "Reverie" << "Prelude"; // Populate our model model->setStringList(List); // Glue model and view together ui->listView->setModel(model);
and it will show your list.
-
Hi
Yes you can create QLables dynamically but it gets heavy fast so as Christian-Ehrlicher says,
a model and a ListView is much more fun.
You could try out with a QStringListModel if you dont plan to show millions of rows.You can see here how to use one.
https://www.bogotobogo.com/Qt/Qt5_QListView_QStringListModel_ModelView_MVC.phpit shows how to add new and remove from the model.
Basically you can place a QListView on the UI form and do
// Create model model = new QStringListModel(this); // its a member // Make data QStringList List; List << "Clair de Lune" << "Reverie" << "Prelude"; // Populate our model model->setStringList(List); // Glue model and view together ui->listView->setModel(model);
and it will show your list.
wrote on 2 Mar 2020, 04:25 last edited by@mrjj @Christian-Ehrlicher Thanks for reply
1/4