[Qt-interest] QRubberBand and set selection in qlistwidget

Puneet Bisht pbisht at nivio.com
Wed Aug 12 09:31:35 CEST 2009



sorry that was silly copy paste error.

I sort out it .
the working code is :
void MyWidget::mousePressEvent(QMouseEvent *event)
 {
     origin = event->pos();
     if (!rubberBand)
         rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
     rubberBand->setGeometry(QRect(origin, QSize()));
     rubberBand->show();
return QListWidget::mousePressEvent(event);
 }

 void MyWidget::mouseMoveEvent(QMouseEvent *event)
 {
     this->setSelection(rubberBand->rect(),QItemSelectionModel::Select);//ClearAndSelect);
            QListWidget::mouseMoveEvent(event);


 }

 void MyWidget::mouseReleaseEvent(QMouseEvent *event)
 {
     rubberBand->hide();
QListWidget::mouseReleaseEvent(event);
   }


Thanks Alex for your reply .

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com]
On Behalf Of Puneet Bisht
Sent: Tuesday, August 11, 2009 12:11 AM
To: Qt-interest at trolltech.com
Subject: [Qt-interest] QRubberBand and set selection in qlistwidget

hi all,

I am facing a problem in selecting the items in a qlistwidget.
Actually i have a class which inherit qlistwidget and i am showing the items
in icon mode .
here in this custom widget i am showing a rubberband like this :

void MyWidget::mousePressEvent(QMouseEvent *event)
 {
     origin = event->pos();
     if (!rubberBand)
         rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
     rubberBand->setGeometry(QRect(origin, QSize()));
     rubberBand->show();
 }

 void MyWidget::mouseMoveEvent(QMouseEvent *event)
 {
     rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
     setSelection(QRect(origin,e->pos()).normalized(),QItemSelectionModel::Select);
//setSelection(rubberBand->rect(),QItemSelectionModel::Select );



 }

 void MyWidget::mouseReleaseEvent(QMouseEvent *event)
 {
     rubberBand->hide();
   }


here all things goes fine but no item is selected .
I am unable to understand why this is happening .
Please help me on this issue .

Thanks in Advance.




More information about the Qt-interest-old mailing list