Results 1 to 4 of 4

Thread: QLabel clickable

  1. #1
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QLabel clickable

    How can I make a QLabel clickable?
    I am trying to make an About.. dialog with a clickable image without buttons.
    MacOSX user dabbling with Linux and Windows.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel clickable

    reimplement mousePressEvent in QLabel class and emit your custom signal
    see this link
    http://doc.trolltech.com/3.3/qwidget...ousePressEvent
    Last edited by wagmare; 29th July 2009 at 06:59. Reason: showing the link for mousePressEvent
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel clickable

    Quote Originally Posted by bnilsson View Post
    How can I make a QLabel clickable?
    I am trying to make an About.. dialog with a clickable image without buttons.
    you have 2 options.
    1. Use QPushButton and make them flat, this will give you same feeling like a label is being clicked.
    2. Use event filter on label, and react on mousepress event. In this method, you dont need to subclass the QLabel.

  4. #4
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel clickable

    Thanks for the advice.
    I replaced the QLabel with a big flat QPushButton and used setIcon(pixmap).
    I also added the clicked() signal and accept() slot for it in the .ui.
    It was the simplest way, works perfectly.

    Again, thanks.
    MacOSX user dabbling with Linux and Windows.

Similar Threads

  1. Trouble with QLabel
    By dany_MB in forum Newbie
    Replies: 3
    Last Post: 14th August 2009, 08:21
  2. Replies: 3
    Last Post: 17th July 2008, 07:43
  3. Clickable Qlabel
    By lewis in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2008, 10:39
  4. QLabel ScaledContents ignored by style sheet?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 27th February 2008, 14:50
  5. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.