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. Checkboxes and spinboxes to list

Checkboxes and spinboxes to list

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 3.4k 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.
  • Q Q139

    Hi,
    How to align text in QlistWidget?
    How to add checkboxes and spinboxes to QlistWidget or QlistView?
    If it all in docs plese point to the right material.

    S Offline
    S Offline
    samdol
    wrote on last edited by
    #3

    @Q139
    You may look into
    http://doc.qt.io/qt-4.8/qt-itemviews-spinboxdelegate-example.html
    It uses QTableView, but you can do the same thing on QListView.

    1 Reply Last reply
    1
    • Q Offline
      Q Offline
      Q139
      wrote on last edited by
      #4

      Thanks for pointing in right direction

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #5

        To add to samdol, here is the same link for Qt 5: Spin Box Delegate Example

        1 Reply Last reply
        3
        • Q Offline
          Q Offline
          Q139
          wrote on last edited by Q139
          #6

          Is it possible to load frame designed via ui designer to list also?

          mrjjM 1 Reply Last reply
          0
          • Q Q139

            Is it possible to load frame designed via ui designer to list also?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #7

            @Q139
            Hi
            Yes you could use UI file but its really not working
            that way and would be very heavy when just a few items in list.

            However, you can easy draw in UI and the just take the code and use.
            ( the UI files is translated to c++ code to create what you have drawn)
            Please see inside the setupUI() found in mainwindow

            Q 1 Reply Last reply
            0
            • mrjjM mrjj

              @Q139
              Hi
              Yes you could use UI file but its really not working
              that way and would be very heavy when just a few items in list.

              However, you can easy draw in UI and the just take the code and use.
              ( the UI files is translated to c++ code to create what you have drawn)
              Please see inside the setupUI() found in mainwindow

              Q Offline
              Q Offline
              Q139
              wrote on last edited by
              #8

              @mrjj Good tips, will just code then.

              mrjjM 1 Reply Last reply
              0
              • Q Q139

                @mrjj Good tips, will just code then.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #9

                @Q139
                :)
                The normal trick is that when editing its real widgets but when not editing the row
                then its just drawn. This is to keep it non heavy.

                But if you only have few items in list, there is also
                http://doc.qt.io/qt-5/qlistwidget.html#setItemWidget

                That lets you set widget with no fuss.
                This solution have bad performance very fast.

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  Q139
                  wrote on last edited by Q139
                  #10

                  That seems easyest way , list will be max 20 item and updated rarely mostly.

                  mrjjM 1 Reply Last reply
                  0
                  • Q Q139

                    That seems easyest way , list will be max 20 item and updated rarely mostly.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @Q139
                    Ok. On a desktop class pc. i had over 1000 with no issue but
                    if you run on weaker devices, redraw can be issue.
                    But not with 20 :)

                    1 Reply Last reply
                    0
                    • Q Q139

                      Hi,
                      How to align text in QlistWidget?
                      How to add checkboxes and spinboxes to QlistWidget or QlistView?
                      If it all in docs plese point to the right material.

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by VRonin
                      #12

                      How to align text in QlistWidget

                      use something like listWidgetItem->setData(Qt::TextAlignmentRole, Qt::AlignCenter); or listWidget->model()->setData(listWidget->model()->index(row,0),Qt::AlignCenter,Qt::TextAlignmentRole);

                      How to add checkboxes

                      use something like listWidgetItem->setFlags(listWidgetItem->flags() | Qt::ItemIsUserCheckable);

                      and spinboxes to QlistWidget or QlistView?

                      Subclass QStyledItemDelegate and set it on the view or, if you just need the editor, subclass QItemeditorFactory and apply it to your default delegate.

                      P.S.
                      Rather than using the Q*Widgets (which I hate) why not separate the model and the view?! http://doc.qt.io/qt-5/model-view-programming.html

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      1
                      • Q Offline
                        Q Offline
                        Q139
                        wrote on last edited by Q139
                        #13

                        Tryed manual code but decided to do design ui to position items better.

                        for(uint n=0; n<set_to_use.extra.corSetVec.size(); n++){
                            if(ui->corSetList->count() <= n){//to initialize more items
                                ui->corSetList->addItem("");
                            }
                            corSetStruct co=set_to_use.extra.corSetVec[n];
                            corSetListComponent * wid = new corSetListComponent;// ui widget
                            wid->setStructToUI(co);// data to ui widget
                            wid->vecIndex=n; 
                            
                            QSize siz; // to set item size
                            siz.setHeight(wid->height());
                            siz.setWidth(ui->corSetList->width()-4); //-4 to avoid creating slider bar
                            ui->corSetList->item(n)->setSizeHint(siz);
                            ui->corSetList->setItemWidget(ui->corSetList->item(n),wid); 
                        }
                        

                        This solved it so far, may not be best code but it work for now.
                        Would qListWidget delete the corSetListComponent * wid = new corSetListComponent; from ram after list item removed?

                        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