Results 1 to 9 of 9

Thread: how to add item in a list widget on clicking of a pushbutton

  1. #1
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default how to add item in a list widget on clicking of a pushbutton

    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
    Attached Files Attached Files
    thanks & regards
    --------------------
    jyoti

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to add item in a list widget on clicking of a pushbutton

    You can't do these from within Designer. Use either multiple or single inheritance approach and create custom slots for doing those tasks.

    Qt Code:
    1. connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(newItem()));
    2.  
    3. void MyForm::newItem()
    4. {
    5. ui.listWidget->addItem(ui.lineEdit->text());
    6. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    jyoti (13th November 2006)

  4. #3
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: how to add item in a list widget on clicking of a pushbutton

    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)......
    thanks & regards
    --------------------
    jyoti

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to add item in a list widget on clicking of a pushbutton

    Quote Originally Posted by jyoti View Post
    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:
    Qt Code:
    1. connect(ui.someButton, SIGNAL(clicked()), this, SLOT(deleteItems()));
    2.  
    3. void MyForm::deleteItems()
    4. {
    5. qDeleteAll(ui.listWidget->selectedItems());
    6. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by jyoti View Post
    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()
    Qt Code:
    1. ui.lineEdit->clear();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. #5
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to add item in a list widget on clicking of a pushbutton

    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.
    We can't solve problems by using the same kind of thinking we used when we created them

  7. #6
    Join Date
    Dec 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Android

    Default Re: how to add item in a list widget on clicking of a pushbutton

    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 ????????????

  8. #7
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to add item in a list widget on clicking of a pushbutton

    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/qlistwidg...urrentRow-prop

  9. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to add item in a list widget on clicking of a pushbutton

    Quote Originally Posted by thekiller View Post
    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
    Qt Code:
    1. #include <QLineEdit>
    To copy to clipboard, switch view to plain text mode 
    3 - please define "don't work".
    4 - additem is a slot? Show you header! use code tags, please!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  10. #9
    Join Date
    Oct 2015
    Location
    bangalore
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default how to append data items from a list widget to another list widget using pushbutton

    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
    Attached Files Attached Files

Similar Threads

  1. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 21:28
  2. Programattically Clicking an Item in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 4
    Last Post: 11th May 2006, 16:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.