Results 1 to 7 of 7

Thread: linkActivated

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default linkActivated

    Hello anyone,

    I have Qt-4.2.2 installed.

    I have in a MainWindow a Label called searchLabel.
    In Qt-4.2 there is a new signal LinkActivated();
    I want to click on the searchLabel to start a another application for example a Dialog.

    In my MainWindow i have the connection:

    Qt Code:
    1. connect(searchLabel, SIGNAL(linkActivated(const QString &)), this, SLOT(search()));
    2.  
    3. void MainWindow::search()
    4. {
    5. searchDialog dlg(this);
    6. if( dlg.exec() == QDialog::Accepted ) {
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Normally in the docs the signal is:
    connect(label_2, SIGNAL(linkActivated(const QString & )), this, SLOT(myslot(const QString &)));

    In my Qt-Designer the flag Qt::LinksAccessibleByMouse is set.

    Nothing happens, no errors in my console.

    Can i use the signal LinkActivated() only for a URL adress?.

    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: linkActivated

    I don't see anything wrong with provided code snippet... Are you sure the connect-statement gets executed and searchLabel exists by that time? Do you see a warning if you intentionally make it fail?
    J-P Nurmi

  3. #3
    Join Date
    Mar 2006
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: linkActivated

    Does the label have a url embedded, or do you just want a signal when the user clicks on the QLabel? If it is the second, then I've subclassed QLabel and added a mouseReleaseEvent

    Qt Code:
    1. class ClickLabel : public QLabel
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ClickLabel(QWidget *parent = 0, Qt::WindowFlags f = 0);
    7. ClickLabel(const QString &text, QWidget *parent = 0, Qt::WindowFlags f = 0);
    8. virtual ~ClickLabel();
    9.  
    10. Q_SIGNALS:
    11. void labelClicked(ClickLabel *);
    12.  
    13. protected:
    14. virtual void mouseReleaseEvent(QMouseEvent * event);
    15. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ClickLabel::ClickLabel(QWidget *parent, Qt::WindowFlags f)
    2. : QLabel(parent, f)
    3. {
    4. }
    5.  
    6.  
    7. ClickLabel::ClickLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
    8. : QLabel(text, parent, f)
    9. {
    10. }
    11.  
    12.  
    13. ClickLabel::~ClickLabel()
    14. {
    15. }
    16.  
    17.  
    18. void ClickLabel::mouseReleaseEvent(QMouseEvent * event)
    19. {
    20. if (event->button() == Qt::LeftButton)
    21. {
    22. emit labelClicked(this);
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 
    Just change searchLabel to a ClickLabel...

  4. #4
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: linkActivated

    A signal when the user clicks on the QLabel
    I've subclassed QLabel and added a mouseReleaseEvent and change searchLabel to ClickLabel.

    Nothing happens.
    In my console no errors.
    I'am doing this on Windows XP with QT-4.2.2 opensource.

    What iám doing wrong.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: linkActivated

    Really hard to say without seeing the code...
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: linkActivated

    Header file:

    Qt Code:
    1. #include "ui_labeldialog.h"
    2.  
    3.  
    4. class labelDialog : public QDialog, Ui::labelDialog
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. labelDialog(QWidget *parent = 0);
    10.  
    11. public slots:
    12. void search();
    13. };
    14.  
    15.  
    16. class ClickLabel : public QLabel
    17.  
    18. {
    19. Q_OBJECT
    20.  
    21. public:
    22. ClickLabel(QWidget *parent = 0, Qt::WindowFlags f = 0);
    23. ClickLabel(const QString &text, QWidget *parent = 0, Qt::WindowFlags f = 0);
    24. virtual ~ClickLabel();
    25.  
    26. Q_SIGNALS:
    27. void labelClicked(ClickLabel *);
    28.  
    29. protected:
    30. virtual void mouseReleaseEvent(QMouseEvent * event);
    31. };
    To copy to clipboard, switch view to plain text mode 

    Implentation file:

    Qt Code:
    1. #include <QtGui>
    2. #include "mainwindow.h"
    3. #include "vhf.h"
    4.  
    5.  
    6. labelDialog::labelDialog(QWidget *parent)
    7. :QDialog(parent)
    8. {
    9.  
    10. setupUi(this);
    11. connect(ClickLabel, SIGNAL(linkActivated(const QString &)), this, SLOT(search()));
    12. }
    13.  
    14. void labelDialog::search()
    15. {
    16. vhfDialog dlg(this);
    17. if( dlg.exec() == QDialog::Accepted ) {
    18. }
    19. }
    20.  
    21. ClickLabel::ClickLabel(QWidget *parent, Qt::WindowFlags f)
    22. : QLabel(parent, f)
    23. {
    24. }
    25.  
    26. ClickLabel::ClickLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
    27. : QLabel(text, parent, f)
    28. {
    29. }
    30.  
    31.  
    32. ClickLabel::~ClickLabel()
    33. {
    34. }
    35.  
    36.  
    37. void ClickLabel::mouseReleaseEvent(QMouseEvent * event)
    38. {
    39. if (event->button() == Qt::LeftButton){
    40. emit labelClicked(this);
    41. }
    42. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: linkActivated

    Well, you're still connecting to linkActivated() signal which gets only emitted if you actually have links in the label. So connect to labelClicked() signal and make sure you promoted the label as ClickLabel in designer. You might need to declare ClickLabel in a separate header to be able to promote in designer.
    J-P Nurmi

Similar Threads

  1. 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.