Results 1 to 17 of 17

Thread: QLabel::clicked()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Location
    Dublin, Ireland
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel::clicked()

    I agree with Lotek.
    A mouse "click" is traditionally a full press-then-release event series.
    Interpreting a click on a mouse press disallows the user from canceling the click when they drag the mouse away from the item, amongst other things.
    Just my two-cents.
    doggy

  2. #2
    Join Date
    Jan 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel::clicked()

    And how to check which label has been clicked if have many????

  3. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    52
    Thanked 42 Times in 42 Posts

    Default Re: QLabel::clicked()

    Using above example if You connect multiple instances of myLabel object into one slot then within that slot You can use sender() to determine what myLabel object send the signal. To have full access You can cast it lik:

    Qt Code:
    1. myLabel *Label = qobject_cast<myLabel *>( this->sender() );
    2. Label->setText( QString( "This sender is: %1" ).arg( this->sender()->objectName() ) );
    To copy to clipboard, switch view to plain text mode 

    Label is pointer to the object that send signal.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  4. #4
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    1

    Default Re: QLabel::clicked()

    thanks to this thread! I'm having the same problem with my project and this works just fine for me. But, in my application, besides emitting the signal after the mouse is clicked/released, I also need to know the coordinates of the clicked point. Is there any way to program this??
    I'm new to Qt and is learning .

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: QLabel::clicked()

    Did you read the docs on QMouseEvent? There are 7 different methods to give you information about the position of the mouse.

    If the slot listening for the clicked() signal needs to know the mouse position, then change the clicked signal to send the position as an argument:

    Qt Code:
    1. // myLabel.h
    2. signals:
    3. void clicked( const QPos & );
    4.  
    5. // myLabel.cpp:
    6.  
    7. void myLabel::mouseReleaseEvent( QMouseEvent * event )
    8. {
    9. emit clicked( event->pos() );
    10. }
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. The following user says thank you to d_stranz for this useful post:

    study24816 (1st August 2012)

  7. #6
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    1

    Default Re: QLabel::clicked()

    I think I've foudn the answer. the pointer *event to QMouseEvent stores the relevant information about the event mousepress/release. I gotta read more about QMouseEvent.

    Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.