2016-04-25 3 views

答えて

1

これらのウィジェットをサブクラス化し、QWidget::mousePressEvent,QWidget::mousMoveEventおよびQWidget::mouseReleaseEventを再実装する必要があります。しかし、デフォルトの実装(例えば、選択)によってマッピングされたアクションに干渉する可能性があるため、少し微調整する必要があるため注意が必要です。例えば(QListViewのサブクラスを想定):

void MyListView::mousePressEvent(QMouseEvent *event) 
{ 
    if(event->button() == Qt::RightButton) //lets map scrolling to right button 
     m_ScrollStart = event.pos(); //QPoint member, indicates the start of the scroll 
    else 
     QListView::mousePressEvent(event); 
} 

、次いで

void MyListView::mouseMoveEvent(QMouseEvent *event) 
{ 
    if(!m_ScrollStart.isNull()) //if the scroll was started 
    { 
     bool direction = (m_ScrollStart.y() < event.pos().y()) //determine direction, true is up (start is below current), false is down (start is above current) 
     int singleStep = (direction ? 10 : -10); //fill in the desired value 
     verticalScrollBar()->setValue(verticalScrollBar()->value() + singleStep); 
     //scroll byt certain amount in determined direction, 
     //you decide how much will be a single step... test and see what you like 
    } 

    QListView::mouseMoveEvent(event); 
} 

、最終的に

void MyListView::mouseReleaseEvent(QMouseEvent *event) 
{ 
    m_ScrollStart = QPoint(); //resets the scroll drag 
    QListView::mouseReleaseEvent(event); 
} 
関連する問題