[Qt-interest] problem in mouseEvent

Srdjan Todorovic todorovic.s at googlemail.com
Thu Apr 9 10:35:29 CEST 2009


Hi,

2009/4/8 chandrasekar wagmare <sekarwagmare at gmail.com>:
> hi friends,
>       i post my entire program here ... can any one please help me to solve
> the problem

It's not the entire program - where's main() ?  ;-)

> ToolTipper::ToolTipper(QWidget *parent)
>           :QWidget(parent ,Qt::ToolTip)
> {
>         QString path = "<font color =red>The communication failed due to
> heavy rain  all network jammed  </font>";
>
>         label = new QLabel();
>         label2 = new QLabel();
>         label2->setGeometry(QRect(0, 0, 116, 121));
>
> label2->setPixmap(QPixmap(QString::fromUtf8(":/images/closeButton2.png")));
>         label2->setScaledContents(true);
>         label->setText(path);
>          QHBoxLayout *horizontalLayout = new QHBoxLayout();
>         horizontalLayout->addWidget(label);
>         horizontalLayout->addWidget(label2);
>          QVBoxLayout *verticalLayout = new QVBoxLayout();
>         verticalLayout->addLayout(horizontalLayout);
>         setLayout(verticalLayout);
>         layout()->setSizeConstraint(QLayout::SetFixedSize);
> }
>
> void ToolTipper::mousePressEvent(QMouseEvent *event)
> {
>      if(event->button() ==  Qt::LeftButton){
>           printf("label2of x() %d and event y() %d \n", label2->x(),
> label2->y());
>                 checkClicked(event->pos());
> }else{
>                 QWidget::mousePressEvent(event);
>                 return ;
>         }
> }
> void ToolTipper::checkClicked( const QPoint &pos)
> {
>         int i = pos.x();
>         int j = pos.y();

Have you checked (printed) that i and j are values that you expect
(ie. within the label's qrect)?


>         if(label->rect().contains(i , j)){

Have you checked that label->rect() is a QRect that you expect?

Maybe write a unit test so that you know what the code is doing.

>                 printf("the position is inside ...\n");
>         }else{
>                 printf("no its not working ...\n");
>         }
>
> }

Hope that helps,

Srdjan



More information about the Qt-interest-old mailing list