PDA

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



jyoti
13th November 2006, 11: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, 11: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, 13: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, 13: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, 13: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.

thekiller
5th December 2012, 11:17
i use the same codes but it dont work.

#include "mainwindow.h"
#include <Qt\qlistwidget.h>
#include <Qt\qlineedit.h>
#include <Qt\qpushbutton.h>
#include <Qt\qlinkedlist.h>

mainwindow::mainwindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
setFixedSize(300,300);
int Top = 0;

liste = new QListWidget(this);
liste->setGeometry(10,10,80,200);

line = new QLineEdit(this);
line->setGeometry(100,10,80,20);

m_buton = new QPushButton("add",this);
m_buton->setGeometry(100,50,80,20);

QObject::connect(m_buton,SIGNAL(clicked()),this,SL OT(additem()));
}





void mainwindow::additem()
{
liste->addItem(new QListWidgetItem(line->text()));
}

anapencere::~anapencere()
{

}

please help where is the mistake ????????????

Gokulnathvc
5th December 2012, 13:01
If you want to delete an item from the list, just select it and click on push button, where it takes the index of the currently selected item, and just delete it.

It is very simple. Just refer the guide. http://doc.qt.digia.com/qt/qlistwidget.html#currentRow-prop

amleto
5th December 2012, 14:07
i use the same codes but it dont work.

#include "mainwindow.h"
#include <Qt\qlistwidget.h>
#include <Qt\qlineedit.h>
#include <Qt\qpushbutton.h>

<SNIP>

please help where is the mistake ????????????

1 - use code tags
2 - qt includes should look like


#include <QLineEdit>

3 - please define "don't work".
4 - additem is a slot? Show you header! use code tags, please!

jayprakash
1st October 2015, 07:23
hi all
my form appears like this(attachment)..
and i want to append data items from a list widget to another list widget using qpushbutton.Tell me the procedure how to do it. How i can use signal &slot to complete this task.
Also please tell me the procedure for remove item(highlightened) from list widget box....

plz do reply as soon as possible..

thanks in advance