PDA

View Full Version : how to add item in a list widget on clicking of a pushbutton


jyoti
13th November 2006, 12:27
hi all
my form appears like this(attachment)...
nw i want when i enter any item_name in a line edit and then i click the pushbutton i.e enter item
then that string of line_edit come in list widget box
n even tell me the procedure for remove item(highlightened) from list widget box....

plz do reply as soon as possible..

thanks in advance

jpn
13th November 2006, 12:42
You can't do these from within Designer. Use either multiple (http://doc.trolltech.com/4.2/designer-using-a-component.html#the-multiple-inheritance-approach) or single inheritance (http://doc.trolltech.com/4.2/designer-using-a-component.html#the-single-inheritance-approach) approach and create custom slots for doing those tasks.

connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(newItem()));

void MyForm::newItem()
{
ui.listWidget->addItem(ui.lineEdit->text());
}

jyoti
13th November 2006, 14:20
thanks alot...
can u further tell how to remove item from list widget.....on clicking of pushbutton
n one thing more in previous query...when we click the pushbutton then line edit text item inserted in list as well as line_edit should be clear n ready to get the next item (i.e insertion for next item)......

jpn
13th November 2006, 14:26
can u further tell how to remove item from list widget.....on clicking of pushbutton
In the same way, just create a custom slot connected to the button's clicked() signal and do the task by hand:

connect(ui.someButton, SIGNAL(clicked()), this, SLOT(deleteItems()));

void MyForm::deleteItems()
{
qDeleteAll(ui.listWidget->selectedItems());
}



n one thing more in previous query...when we click the pushbutton then line edit text item inserted in list as well as line_edit should be clear n ready to get the next item (i.e insertion for next item)......
QLineEdit::clear()

ui.lineEdit->clear();

sunil.thaha
13th November 2006, 14:34
Before that read the docs!

All the questions you asked, simply proves that you have not read the docs properly.
Next time, you post, Only thing you need to do is to state the requirements

We will do the job for you.