Re: problem in mouseEvent
From QWidget::rect docs:
Quote:
The rect property equals QRect(0, 0, width(), height()).
Re: problem in mouseEvent
Quote:
Originally Posted by
jpn
thanks for reply ...
but the docs tells
bool QRect::contains ( const QPoint & point, bool proper = false ) const
Returns true if the the given point is inside or on the edge of the rectangle, otherwise returns false. If proper is true, this function only returns true if the given point is inside the rectangle (i.e., not on the edge).
so how can i handle this ... how to use QRect::Contains() function .. is there any alternative ..
Re: problem in mouseEvent
assuming you are handling this mouse event in your custom widget, pos() is returning point relative to the custom widget..not relative to the label..so use mapFromParent(assuming the custom widget is the parent) to get point relative to your own label widget..then use rect.contains(..)
Re: problem in mouseEvent
Ok, so you want to know WHERE the label is, to be able to check whether some coordinates are inside it or not. Your problem is that QWidget::rect() does not tell you WHERE the label is, it returns an INTERNAL rectangle where top left corner is always (0,0). Please refer to the geometry documentation as proposed by the QWidget::rect docs.
Re: problem in mouseEvent
i posted my entire code ...
Code:
ToolTipper
::ToolTipper(QWidget *parent
){
QString path
= "<font color =red>The communication failed due to heavy rain all network jammed </font>";
label2
->setGeometry
(QRect(0,
0,
116,
121));
label2
->setPixmap
(QPixmap(QString::fromUtf8(":/images/closeButton2.png")));
label2->setScaledContents(true);
label->setText(path);
horizontalLayout->addWidget(label);
horizontalLayout->addWidget(label2);
verticalLayout->addLayout(horizontalLayout);
setLayout(verticalLayout);
layout
()->setSizeConstraint
(QLayout::SetFixedSize);
and in same class a mouseEvent
Code:
{
if(event->button() == Qt::LeftButton){
checkClicked(event->pos());
}else{
return ;
}
Code:
void ToolTipper
::checkClicked( const QPoint &pos
) {
int i = pos.x();
int j = pos.y();
if(label->rect().contains(i , j)){
printf("the position is inside ...\n");
}else{
printf("no its not working ...\n");
}
}
here if it is label .. checkClicked() prints "the position is inside ..." but if i replace label to label2 ie the label with pixmap checkClicked() prints "no its not working ..."
i dont know what is the difference b/w a label and label with pixmap .... please help
Re: problem in mouseEvent
Did you consider mapping the position from local to parent / global and then checking the condition, as said earlier by amulya ??
please give time to understand what is being said to you. And also Assistant has quite good details about the geometry.
Re: problem in mouseEvent
Quote:
Originally Posted by
aamer4yu
Did you consider mapping the position from local to parent / global and then checking the condition, as said earlier by amulya ??
please give time to understand what is being said to you. And also Assistant has quite good details about the geometry.
sorry ..
yes i am trying only what amulya told me ... but i just posted with one doubt only ... the parent is having two label ... contains work on one label but not on another label ... its different doubt ... i am following only what u , amulya and jpn told me ...