Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
I want to show a outer enclosing rectangle border for QWidget while the mouse moves In (enterEvent()) but disappeared when mouse moves out (leaveEvent()).



I have tried to subClass a QWidget and override the paintEvent();
C#
void QImageLabel::enterEvent(QEvent * event)
{
    QLabel::enterEvent(event);
    //draw frame
    m_bDrawBorder =true;
    update();
}

void QImageLabel::leaveEvent(QEvent * event)
{
    QLabel::leaveEvent(event);
    //dismiss the frame
    m_bDrawBorder = false;
    update();
}

C#
void QImageLabel::paintEvent(QPaintEvent *aPaintEvent)
{
	if(m_bDrawBorder)
	{
		QPainter painterParent(parentWidget() ? parentWidget() : QApplication::desktop());
		//painter.save();
		QRect rectc = geometry();
		rectc.adjust(-2,-2,2,2);
		QPen pen(Qt::darkCyan);
		pen.setWidth(2);
		painterParent.setPen(pen);
		painterParent.drawRect(rectc);
	}
	QLabel::paintEvent(aPaintEvent);
}


But nothing appeared? (BTW,I can use this method to draw a internal rectangle border)

Do I must to achieve in the parent level? (e.g by install eventFilter() for that child or override the mouseMove() and detect if the cursor is above that child?)
if so, Is possible to achieve it inside the child widget?

any hint?

thanks!
Posted
Updated 25-Dec-14 18:10pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900