2011-04-10 3 views
1

타원의 색상을 마우스로 움직이면 타원의 색을 변경하고 싶습니다. 그러나 Qt Creator에서 참조 및 자동 완성 기능을 찾지 못했습니다.Qt 크리에이터, C++, 마우스 오버 기능

어떻게 할 수 있는지 알고 계십니까?

내 코드의 일부 :

void DrawingWidget::paintEvent(QPaintEvent *event) { 
    QPainter painter(this); 
    painter.fillRect(event->rect(), Qt::white); 

    for(int i = 0; i < pointList.size(); i++) { 
     if (pointList[i].x() >= 0 && pointList[i].y() >= 0) 
      painter.drawEllipse(pointList[i], 10, 10); 
    } 
    painter.drawLines(lineList); 
    m_mainWindow->updateCount(); 
} 

마우스를 눌러 이벤트 핸들러 :

void DrawingWidget::mousePressEvent(QMouseEvent *event) { 
    if (event->button() == Qt::LeftButton 
     && event->buttons() == Qt::LeftButton) { 
     // DO STUFFF 
    } 
} 

마우스 이동 이벤트 핸들러 :

void DrawingWidget::mouseMoveEvent(QMouseEvent *event) { 
    if (m_mainWindow->getSelectedTool() == MainWindow::moveVertexTool) { 
     m_x = event->x(); 
     m_y = event->y(); 
     if (isPointNear(m_x, m_y)) { 
      //STUFF 
     } 
      update(); 
     } 
    } 
} 

지금 난 그냥 이벤트를 통해 마우스 필요 (매니저).

+0

코드의 간단한 스 니펫을 게시하십시오. 이 시점에서 우리는 귀하의 자동 완성 기능보다 적은 것을 여전히 알고 있습니다 ... –

+0

. QWidget 또는 QGraphicsItem입니까? –

+0

@Greg Hewgill, @Stephan Chu : 본편에 스 니펫을 추가했습니다. – Jaanus

답변

5

나는 당신이 찾고있는 것이 enterleave 이벤트라고 생각합니다.

1

QWidget::underMouse()을 사용하여 위젯이 마우스 커서 아래에 있는지 확인하십시오. 예를 들어

:

void IconButton::paintEvent(QPaintEvent *) 
{ 
    QPainter painter(this); 

    // Note isDown should really use the active state but in most styles 
    // this has no proper feedback 
    QIcon::Mode mode = QIcon::Disabled; 
    if (isEnabled()) { 
     if (isDown()) 
      mode = QIcon::Selected; 
     else 
      mode = underMouse() ? QIcon::Active : QIcon::Normal; 
    } 
    QPixmap pixmap = icon().pixmap(iconSize(), mode); 

    QRect pixmapRect = QRect(0, 0, pixmap.width(), pixmap.height()); 
    pixmapRect.moveCenter(rect().center()); 

    if (m_autoHide) 
     painter.setOpacity(m_iconOpacity); 

    painter.drawPixmap(pixmapRect, pixmap); 
} 

이 값은 드래그 앤 드롭 작업 중에 제대로 업데이트되지 않습니다.