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. Code for Click on QLabel!?
Forum Updated to NodeBB v4.3 + New Features

Code for Click on QLabel!?

Scheduled Pinned Locked Moved General and Desktop
16 Posts 7 Posters 20.0k 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.
  • F Offline
    F Offline
    favoritas37
    wrote on last edited by
    #4

    You can create a class that inherits from QLabel which will implement the following protected function:
    @
    signals:
    void clicked();
    protected:
    void mousePressEvent ( QMouseEvent * evt);
    void mouseReleaseEvent ( QMouseEvent * evt);
    @

    You could set it to emit a clicked signal every time mouseReleaseEvent function is called.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fguimaraes
      wrote on last edited by
      #5

      You shoud ceate a SLOT to receive the signal from your QLabel. Try this:
      @
      connect(your_label, SIGNAL(clicked()), this, SLOT(onClicked()));
      @

      Birth, death, rebirth, though, and constantly progress, that is the law.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rahul Das
        wrote on last edited by
        #6

        There is no clicked signal in QLabel.


        Declaration of (Platform) independence.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #7

          I don't see the point in using a clickable label; use either a button or a link (with an appropriate style).

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #8

            I agree with fluca1978: why do you want to confuse the user by making something that doesn't hint at being clickable an active component?

            1 Reply Last reply
            1
            • F Offline
              F Offline
              fguimaraes
              wrote on last edited by
              #9

              Sorry, my mistake. But, as fluca said you can use a pushbutton and change the appearance through QSS.

              [quote author="Rahul Das" date="1323084178"]There is no clicked signal in QLabel.[/quote]

              Birth, death, rebirth, though, and constantly progress, that is the law.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rahul Das
                wrote on last edited by
                #10

                bq.as fluca said you can use a pushbutton and change the appearance through QSS.

                QPushButton::setFlat(true) will also do :) (which i have already told^)


                Declaration of (Platform) independence.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Rahul Das
                  wrote on last edited by
                  #11

                  "Here":http://developer.qt.nokia.com/wiki/How_do_Qlabel_be_clickable you can find the source for 'click'able QLabel

                  //Off Topic : edit link of previous post is not working for me. :(
                  Anybody has the same problem ?


                  Declaration of (Platform) independence.

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    favoritas37
                    wrote on last edited by
                    #12

                    You have the option to make it emit the clicked signal either when mouse gets pressed or when mouse gets release (i prefer the second one). Whatever feels better to you.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Rahul Das
                      wrote on last edited by
                      #13

                      yea, and there is a "how to":http://developer.qt.nokia.com/wiki/How_do_Qlabel_be_clickable / wiki page to do this saying the same as favoritas37 said :)

                      [quote author="favoritas37" date="1323012419"]You can create a class that inherits from QLabel which will implement the following protected function:
                      @
                      signals:
                      void clicked();
                      protected:
                      void mousePressEvent ( QMouseEvent * evt);
                      void mouseReleaseEvent ( QMouseEvent * evt);
                      @

                      You could set it to emit a clicked signal every time mouseReleaseEvent function is called.[/quote]


                      Declaration of (Platform) independence.

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        favoritas37
                        wrote on last edited by
                        #14

                        Rahul, i hope you don't mind, i edited the wiki by removing the slot because it caused the signal to be emitted 2 times. And also i changed the name of the new class to ClickableLabel since this is how it is mentioned in the description. Is that ok?

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          Rahul Das
                          wrote on last edited by
                          #15

                          Thanks, and thats perfect. :) Two times the same signal, was a careless part anyway.
                          [quote author="favoritas37" date="1323115942"]Rahul, i hope you don't mind, i edited the wiki by removing the slot because it caused the signal to be emitted 2 times. And also i changed the name of the new class to ClickableLabel since this is how it is mentioned in the description. Is that ok?[/quote]


                          Declaration of (Platform) independence.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            absfrm
                            wrote on last edited by
                            #16

                            hi again
                            flat property was grate.
                            :)
                            thanks to all about help me in this case .
                            Best regards

                            If You Want You Can!

                            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