Results 1 to 7 of 7

Thread: linkActivated

Hybrid View

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

    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 

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

    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, 15: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.