PDA

View Full Version : QListWidget, how to copy selected items to clipboard



mnrao1230
22nd February 2012, 11:55
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

Zlatomir
22nd February 2012, 13:05
Use the text (http://developer.qt.nokia.com/doc/qt-4.8/qlistwidgetitem.html#text) member function of QListWidgetItem.

mnrao1230
23rd February 2012, 05:11
Thank you for the response... Its Working now :)

mnrao1230
24th February 2012, 10:54
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