[Qt-interest] problem in mouseEvent

chandrasekar wagmare sekarwagmare at gmail.com
Wed Apr 8 12:24:23 CEST 2009


hi friends,
      i post my entire program here ... can any one please help me to solve
the problem

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();

        if(label->rect().contains(i , j)){
                printf("the position is inside ...\n");
        }else{
                printf("no its not working ...\n");
        }

}


here in this code ... in checkClicked if the label->rect().contains(i , j)
ie the normal QString label "label"
            mouseClick event produce the "position is inside .." value when
clicked on it ... and   "no its not working"  if clicked outside it ...  ie
the Qrect::contains returns TRUE ..

but ..... if i use in checkClicked if the label2->rect().contains(i , j)
ie the pixmap label "label2"
            mouseClick event always producing  "no its not working" ... ie
the Qrect::contains returns FALSE .. even clicking on the label2 ...
         why ..... can any body help me ...

-- 
CHANDRU
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090408/bdd847da/attachment.html 


More information about the Qt-interest-old mailing list