List of editable labels on dockwidget
-
hello to the whole community Qt Forum,
I would like to create a Label list, or something equivalent, in a dockwidget in a window; This list must be dynamic, in practice it represents a list of connected users, and I need a way to represent it.
I hope I was clear
Thanks in advance :) -
Hi,
Do you mean something like a QListWidget ? Or QListView with a QStandardItemModel storing your connected users information ?
-
QDockWidget is just a container widget, that's currently not your main concern.
Did you already read the Model/View Programming chapter in Qt's documentation ?
-
@SGaist
I wrote these lines, I would like to know how I can go from this to a direct access visualization model.QWidget* multiWidget = new QWidget(); QScrollArea* area = new QScrollArea(); area->setWidget(multiWidget); QVBoxLayout* layout = new QVBoxLayout(); multiWidget->setLayout(layout); area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); area->setWidgetResizable(true); QVector<QLabel*> ql; for (int i = 0; i < 50; i++) ql.push_back(new QLabel("Label "+i)); for (int i = 0; i < 50; i++) { layout->addWidget(ql[i]); } qw->setWidget(area);//qw is the dockwidget
-
Hi
int nrow = 4; int ncol = 1; // create QListView auto listView = new QListView(this); // create the model QStandardItemModel *model = new QStandardItemModel( nrow, ncol, this ); //fill the model for ( int r = 0; r < nrow; r++ ) { QString sstr = "( " + QString::number(r) + " )"; QStandardItem *item = new QStandardItem(sstr); model->setItem(r, 0, item); } //set model to the view listView->setModel(model);
Then assign listView to a layout that you have put on qw.
ListView can do its own scrolling so no need for ScrollArea. -
Why do you want to use labels ? QListView already provides the necessary plumbing to edit the content of the model.