Results 1 to 2 of 2

Thread: Click on a qlabel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Posts
    33
    Qt products
    Qt4

    Default Click on a qlabel

    Hi,

    I created an array of QLabel on my form:

    QLabel * lblPulsante = new QLabel (this);
    Pulsante[i]= lblPulsante;

    Now, I need to intercept the events click on my QLabel, but I do not know how to do.

    I suppose I must to add something in the:

    private slots: (in the file mainwindow.h) but I don't know the sintax.

    Help me please..........thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Click on a qlabel

    Qt Code:
    1. QLabel * lblPulsante = new QLabel (this);
    2. Pulsante[i]= lblPulsante;
    To copy to clipboard, switch view to plain text mode 
    I take it that this code is part of a loop?
    Using a container would be better and safer, such a QList or QVector.
    But at all having an array of widgets in such as way is very suspicious.
    Arrays are good for managing large sets - but widgets usually are not that many - so usually its better to have a variable per widget - and use a QList of pointers to these widgets in addition if you need to perform actions on all of them.

    To your question:
    You can either subclass your QLabel and overload the mouse events - or, you can install an event filter.
    http://qt-project.org/doc/qt-4.8/qob...e-f62fd93bd477
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 7th May 2011, 20:24
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Replies: 6
    Last Post: 5th June 2009, 09:38
  4. Replies: 2
    Last Post: 11th January 2009, 23:24
  5. Replies: 5
    Last Post: 12th January 2006, 15:40

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.