Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How can a label be linkable not to a website but to a void funtion of the program?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How can a label be linkable not to a website but to a void funtion of the program?

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 5.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #5

    Well even if i dont assign it by UI but create it with ur code it's the same error about the emit not beeing declared..

    1 Reply Last reply
    0
    • U Offline
      U Offline
      utcenter
      wrote on last edited by
      #6

      In that case I don't know, it works for me, emit is the standard Qt keyword to emit a signal. Do you have the Q_OBJECT macro in the header of MyLabel as in my example?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #7

        There is no need to subclass QLabel.

        Just set "openExternalLinks":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#openExternalLinks-prop to false on connect to the "linkActivated":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#linkActivated signal.
        @
        ui->label->setOpenExternalLinks(false);
        connect(ui->label, SIGNAL(linkActivated(QString)), this, SLOT(label_clicked(QString)));

        void MainWindow::label_clicked(const QString &link)
        {
        if (link == "...") ...
        }
        @

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Leon
          wrote on last edited by
          #8

          [quote author="Lukas Geyer" date="1358770207"]There is no need to subclass QLabel.

          Just set "openExternalLinks":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#openExternalLinks-prop to false on connect to the "linkActivated":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#linkActivated signal.
          @
          ui->label->setOpenExternalLinks(false);
          connect(ui->label, SIGNAL(linkActivated(QString)), this, SLOT(label_clicked(QString)));

          void MainWindow::label_clicked(const QString &link)
          {
          if (link == "...") ...
          }
          @[/quote]

          and how should the text of the label be?
          how will it be clickable(linkable).?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Code_ReaQtor
            wrote on last edited by
            #9

            [quote author="Leon" date="1358781102"]

            and how should the text of the label be?
            how will it be clickable(linkable).?

            [/quote]

            The text SHOULD be in "Rich text" , AFAIK.

            Please visit my open-source projects at https://github.com/Code-ReaQtor.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Leon
              wrote on last edited by
              #10

              [quote author="Code_ReaQtor" date="1358782000"]
              [quote author="Leon" date="1358781102"]

              and how should the text of the label be?
              how will it be clickable(linkable).?

              [/quote]

              The text SHOULD be in "Rich text" , AFAIK. [/quote]

              I know that.. You click change rich text in the designer and there is a button "Insert link".

              What should i put there when i want the label_clicked void to be called..?

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #11

                Whatever you like.

                @
                ui->label->setText("This is text with a <a href='someLink'>link</a>.");

                void MainWindow::label_clicked(const QString &link)
                {
                if (link == "someLink") ...
                }
                @

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  Leon
                  wrote on last edited by
                  #12

                  [quote author="Lukas Geyer" date="1358782837"]Whatever you like.

                  @
                  ui->label->setText("This is text with a <a href='someLink'>link</a>.");

                  void MainWindow::label_clicked(const QString &link)
                  {
                  if (link == "someLink") ...
                  }
                  @[/quote]

                  Didn't know that, thanks! :)

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Leon
                    wrote on last edited by
                    #13

                    [quote author="utcenter" date="1358720224"]In that case I don't know, it works for me, emit is the standard Qt keyword to emit a signal. Do you have the Q_OBJECT macro in the header of MyLabel as in my example?[/quote]

                    And by the way, yes i was using
                    #define QT_NO_KEYWORDS

                    I just saw it...

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #14

                      You're welcome! ;-)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved