Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. List of editable labels on dockwidget
QtWS25 Last Chance

List of editable labels on dockwidget

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 373 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danga96
    wrote on last edited by
    #1

    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 :)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean something like a QListWidget ? Or QListView with a QStandardItemModel storing your connected users information ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • D Offline
        D Offline
        danga96
        wrote on last edited by
        #3

        @SGaist
        Thank you for your reply; could you tell me how I can use the QstandardItemModel library with the QListView in a dockWidget?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            danga96
            wrote on last edited by
            #5

            @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
            
            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              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.

              1 Reply Last reply
              1
              • D Offline
                D Offline
                danga96
                wrote on last edited by
                #7

                @mrjj
                Thank you for your reply; I tried its code, and it does just what I wanted, now I'd like to know how to do this with labels, because the QstandarItem constructor doesn't accept Qlabel as a parameter.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Why do you want to use labels ? QListView already provides the necessary plumbing to edit the content of the model.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    danga96
                    wrote on last edited by
                    #9

                    Yes indeed, you're right, with QListView I managed to get the same thing;
                    Thank you all;

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved