Results 1 to 4 of 4

Thread: QListWidget, how to copy selected items to clipboard

  1. #1
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QListWidget, how to copy selected items to clipboard

    Hi,

    I am new to QT. I have a problem- How to copy selected items of QListwidget to clipboard.
    I tried the following -
    void Properties::keyPressEvent(QKeyEvent *k)
    {
    if (k->matches(QKeySequence::Copy))
    {
    // I am getting the selected items from the QListWidget
    QList<QListWidgetItem *> lw_temp = testWidget->lw_props_sample->selectedItems ();
    int itemsCount = testWidget->lw_props_sample->selectedItems ().count();
    QStringList strings;
    for (int i = 0; i < itemsCount; ++i)
    {
    strings.append(lw_temp.value(i)); // I am getting problem in this line. How to get the string value from the list and append it to QStringList
    }

    QApplication::clipboard()->setText(strings.join("\n"));
    }

    Error: error C2664: 'append' : cannot convert parameter 1 from 'class QListWidgetItem *' to 'const class QString &' at line:

    Please help me...

    thanks in Advance,
    Prabhakar

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QListWidget, how to copy selected items to clipboard

    Use the text member function of QListWidgetItem.

  3. #3
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget, how to copy selected items to clipboard

    Thank you for the response... Its Working now

  4. #4
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget, how to copy selected items to clipboard

    Hi Zlatomir,

    I would like to know whether "k->matches(QKeySequence::Copy)" will work for all the OS Platforms or not.

    I tested this with the Windows and it worked fine. I would like to know if it works for Solaris and Linux also?


    thanks,
    Prabhakar

Similar Threads

  1. Replies: 2
    Last Post: 22nd November 2010, 21:49
  2. copy - paste clipboard contents
    By viswanathan in forum Newbie
    Replies: 1
    Last Post: 8th January 2010, 12:10
  3. qlistwidget count of selected items
    By tpf80 in forum Newbie
    Replies: 4
    Last Post: 10th December 2009, 13:31
  4. Problem with copy text to clipboard
    By weiching in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2008, 12:44
  5. How to copy QTableWidget to Clipboard
    By ranna in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2008, 15:47

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.