Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, April 2007
QListWidget swap item with neighbor


Message 1 in thread

Hello Guys,
I am just learning QT4 and python, and have a few questions.

How do I swap a selected QListWidget item with the one above or below 
it? And how can I tell how many items a QListView has since it seems to 
be missing count()?

BTW, this is all QT4

Thanks!
Lawrence

--
 [ signature omitted ] 

Message 2 in thread

Lawrence,

The following will perform a swap of items in the QListWidget called Builder.  The code is for QString items, but would apply for others as well.

void Builder::swapItem( int updown)
{
  int linenumber = this->currentRow();

  if( linenumber + updown < this->count())  // can't swap last item with item below
  {
    QListWidgetItem *container1 = this->currentItem();
    QString item = container1->text();  // get string
    this->takeItem( linenumber);        // delete the string
    this->insertItem( linenumber + updown, item); // place string above or below
  }
}

Don Ware
http://webpages.charter.net/dware1/

----- Original Message ----- 
From: Lawrence Shafer 
To: qt-interest@xxxxxxxxxxxxx 
Sent: Saturday, April 14, 2007 7:02 PM
Subject: QListWidget swap item with neighbor


Hello Guys,
I am just learning QT4 and python, and have a few questions.

How do I swap a selected QListWidget item with the one above or below 
it? And how can I tell how many items a QListView has since it seems to 
be missing count()?

BTW, this is all QT4

Thanks!
Lawrence