You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

bibax

Trainee

  • "bibax" is male
  • "bibax" started this thread

Posts: 53

Location: Nantes, France

  • Send private message

1

Thursday, March 24th 2005, 3:03pm

mouse's coordinates

Hi all,

I have a problem with QMouseEvent.
I try to display my mouse's coordinates but how can I see them?

I tried to display them into a QLineEdit but when I translate int in QString, the QString is empty... ?(

This is my code (Do you see errors?) :
bool conversionTif2bsb::eventFilter( QObject *o, QEvent *e)
{
if(o == _imageFils)
{
//on regarde si un dbl click est effectué
if( e->type() == QEvent::MouseButtonDblClick)
{
QMouseEvent *m = (QMouseEvent *) e;
// x position in leWidth
QString result;
QString buff;
result = buff.arg(m->x(),0,10);
if(result.isEmpty())
{
leWidth->setText("empty"); // I always have empty
}
else
{
leWidth->setText(result);
}
return TRUE;
}
else
{
return false;
}
}
else
{
//when none events
// standard event processing
return FALSE;
}
}



Thx for your replies

Have a nice day 8)
bibax en fait un max

2

Thursday, March 24th 2005, 3:56pm

RE: mouse's coordinates

I think you need a construct like

Source code

1
result=QString("%1").args(m->x(),0,10);
if you really want to use args (see example included in documentation of QString::args())
In my opinion the better way would be using the static QString::number() method. With this you can also omit the second QString buff on the stack:

Source code

1
2
QString result;
result=QString::number(m->x(),10);


The erroro checking (==empty) could be done before that directly on the integer value m->x()

Happy coding...
There's no place like ::1

bibax

Trainee

  • "bibax" is male
  • "bibax" started this thread

Posts: 53

Location: Nantes, France

  • Send private message

3

Friday, March 25th 2005, 9:36am

Thx for your reply

Hi,
I never saw this function before but it's great.
It's so easy that it's funny.

It seems to succeed only with this :

QString result;
result=QString::number(m->x());

Thx for all.

Great sun in France so... Have a nice day 8)
bibax en fait un max