Home > other >  Consult everybody, how in LISTWIDGET, a line add two items or two ICON? thank you
Consult everybody, how in LISTWIDGET, a line add two items or two ICON? thank you

Time:11-24

As title, thank you

CodePudding user response:

you need to set up three things
1. QWidget * widget=new QWidget ();

2. Is the item you want to build (such as label, button)
QLabel * lab1=new QLabel ();
QLabel * lab2=new QLabel ();
QLabel * lab3=new QLabel ();
QPushButton * btn1=new QPushButton ();
3. Create a layout QHBoxLayout *=new QHBoxLayout (widget);
And set up layout inside your entries added:

Layout - & gt; AddWidget (lab1);
Layout - & gt; AddWidget (lab2);
Layout - & gt; AddWidget (lab3);
Layout - & gt; AddWidget (btn1);
Add your label and button to set a name with the setText, then in the widget - & gt; SetLayout (layout);

last as long as you in your listwidget addItem, then setItemWidget (item variable name, widgets), it is good,

this idea is: to create your entry to put them into a widget, then add listwidget items, setting up setItemWidget put you build widgets in go well,
QListWidgetItem * aItem=new QListWidgetItem ();
The UI - & gt; ListWidget - & gt; AddItem (aItem);
The UI - & gt; ListWidget - & gt; SetItemWidget (aItem, widget);

  • Related