Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Code for Click on QLabel!?

    General and Desktop
    7
    16
    19126
    Loading More Posts
    • 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.
    • A
      absfrm last edited by

      Hi
      I want to generate code for Clicked on QLabel event such as QpushButton
      but QLable just has these events :
      @
      LinkActivated();
      linkHovered();
      destroyed();
      customContextMenuRequested();
      @
      can i do it?

      If You Want You Can!

      1 Reply Last reply Reply Quote 0
      • R
        RazrFalcon last edited by

        You can use "eventFilter":http://doc.qt.nokia.com/latest/qobject.html#eventFilter for this.

        1 Reply Last reply Reply Quote 0
        • R
          Rahul Das last edited by

          Are you trying to make the label work like a button ? In that case ,one easy way is to use QPushButton::setFlat(true) to set the 'flat' property and the button will look like a label.
          Or are you completely customizing the QLabel ?


            Rahul Das
          

          1 Reply Last reply Reply Quote 0
          • F
            favoritas37 last edited by

            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 Reply Quote 0
            • F
              fguimaraes last edited by

              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 Reply Quote 0
              • R
                Rahul Das last edited by

                There is no clicked signal in QLabel.


                  Rahul Das
                

                1 Reply Last reply Reply Quote 0
                • F
                  fluca1978 last edited by

                  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 Reply Quote 0
                  • A
                    andre last edited by

                    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 Reply Quote 1
                    • F
                      fguimaraes last edited by

                      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 Reply Quote 0
                      • R
                        Rahul Das last edited by

                        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^)


                          Rahul Das
                        

                        1 Reply Last reply Reply Quote 0
                        • R
                          Rahul Das last edited by

                          "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 ?


                            Rahul Das
                          

                          1 Reply Last reply Reply Quote 0
                          • F
                            favoritas37 last edited by

                            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 Reply Quote 0
                            • R
                              Rahul Das last edited by

                              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]


                                Rahul Das
                              

                              1 Reply Last reply Reply Quote 0
                              • F
                                favoritas37 last edited by

                                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 Reply Quote 0
                                • R
                                  Rahul Das last edited by

                                  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]


                                    Rahul Das
                                  

                                  1 Reply Last reply Reply Quote 0
                                  • A
                                    absfrm last edited by

                                    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 Reply Quote 0
                                    • First post
                                      Last post