Checkboxes and spinboxes to list
-
Hi! You need to subclass
QListWidgetItem
, see QListWidgetItem Class. -
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. -
To add to samdol, here is the same link for Qt 5: Spin Box Delegate Example
-
@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 -
@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 -
@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#setItemWidgetThat lets you set widget with no fuss.
This solution have bad performance very fast. -
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.How to align text in QlistWidget
use something like
listWidgetItem->setData(Qt::TextAlignmentRole, Qt::AlignCenter);
orlistWidget->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 -
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 thecorSetListComponent * wid = new corSetListComponent;
from ram after list item removed?