i posted my entire 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);
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);
To copy to clipboard, switch view to plain text mode
and in same class a mouseEvent
{
if(event->button() == Qt::LeftButton){
checkClicked(event->pos());
}else{
return ;
}
void ToolTipper::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton){
checkClicked(event->pos());
}else{
QWidget::mousePressEvent(event);
return ;
}
To copy to clipboard, switch view to plain text mode
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");
}
}
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");
}
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks