Results 1 to 4 of 4

Thread: linkActivated signal in QLabel?

  1. #1
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default linkActivated signal in QLabel?

    hi friends,
    I used a qlabel .I want to call a customized SLOT on the click of QLabel.
    But it is not working for me ..................
    i used the following code:
    tabwindow.cpp

    Qt Code:
    1. TabWindow::TabWindow(QWidget *parent): QWidget(parent)
    2. {
    3. onlinelabel = new QLabel(this);
    4. onlinelabel->setText(tr("label"));
    5. onlinelabel->setGeometry(11,46,50,16);
    6. connect(onlinelabel,SIGNAL(linkActivated(QString)),this,SLOT(showmenu(QString)));
    7. }
    8.  
    9. void TabWindow::showmenu(const QString & link)
    10. { //some code
    11. }
    To copy to clipboard, switch view to plain text mode 

    tabwindow.h
    Qt Code:
    1. class TabWindow : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. TabWindow(QWidget *parent = 0);
    6. QLabel *onlinelabel;
    7. public slots:
    8. void showmenu(const QString & link);
    9. };
    To copy to clipboard, switch view to plain text mode 

    What i am doing wrong??

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: linkActivated signal in QLabel?

    linkActivated is emitted if you click a HTML link (a). And since you set the text 'label' the signal newer will get emitted. And it seems to me you may will have a look at QPushButton or QToolButton to get a "label" with a menu...

  3. The following user says thank you to Lykurg for this useful post:

    anupamgee (27th April 2009)

  4. #3
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: linkActivated signal in QLabel?

    If you want QLabel with signal clicked() try this:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QtGui/QMouseEvent>
    3. #include <QtGui/QLabel>
    4.  
    5. class QExLabel : public QLabel
    6. {
    7. Q_OBJECT
    8. public:
    9. QExLabel(QWidget *parent = 0) : QLabel(parent){};
    10. signals:
    11. void clicked();
    12. protected:
    13. void mouseReleaseEvent(QMouseEvent *e)
    14. {
    15. if(e->button() == Qt::LeftButton)
    16. {
    17. emit clicked();
    18. }
    19. }
    20. };
    21.  
    22. int main(int argc, char **argv)
    23. {
    24. QApplication app(argc, argv);
    25. QExLabel label;
    26. QObject::connect(&label, SIGNAL(clicked()), &app, SLOT(quit()));
    27. label.show();
    28. return app.exec();
    29. }
    30.  
    31. #include <main.moc>
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: linkActivated signal in QLabel?

    Quote Originally Posted by SABROG View Post
    If you want QLabel with signal clicked() try this:
    This isn't a reaction a user would expect. Why: you press the mouse anywhere down, move it over the label and then release it. In you case the signal would be emitted. But normally you also have to check if the mouse was pressed down over your label.

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Replies: 3
    Last Post: 17th July 2008, 07:43
  4. QLabel text change signal question
    By MarkoSan in forum Newbie
    Replies: 10
    Last Post: 5th April 2008, 10:19
  5. QLabel's linkActivated() signal in QT 4.2
    By gsQT4 in forum Qt Programming
    Replies: 9
    Last Post: 16th March 2007, 14:32

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.