c++ - How QTableView or QListView is scrolling with hand drag? -
in qgraphicview,
if set :     ui->graphicsview->setdragmode(qgraphicsview::scrollhanddrag);
this code make graphicsview can scroll items mouse pressed , drag.
how can make qlistview or qtableview qgraphicsview?
you need subclass these widgets , reimplement qwidget::mousepressevent, qwidget::mousmoveevent , qwidget::mousereleaseevent. have careful because may interfering actions mapped these default implementations (e.g. selecting) need tweaked bit. example (assumed subclass of qlistview):
void mylistview::mousepressevent(qmouseevent *event) {     if(event->button() == qt::rightbutton) //lets map scrolling right button         m_scrollstart = event.pos(); //qpoint member, indicates start of scroll     else         qlistview::mousepressevent(event); } and then
void mylistview::mousemoveevent(qmouseevent *event) {     if(!m_scrollstart.isnull()) //if scroll started     {         bool direction = (m_scrollstart.y() < event.pos().y()) //determine direction, true (start below current), false down (start above current)         int singlestep = (direction ? 10 : -10); //fill in desired value         verticalscrollbar()->setvalue(verticalscrollbar()->value() + singlestep);          //scroll byt amount in determined direction,         //you decide how single step... test , see      }      qlistview::mousemoveevent(event); } and finally
void mylistview::mousereleaseevent(qmouseevent *event) {     m_scrollstart = qpoint(); //resets scroll drag     qlistview::mousereleaseevent(event); } 
Comments
Post a Comment