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. QLabel and right click
Forum Updated to NodeBB v4.3 + New Features

QLabel and right click

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 4 Posters 1.5k 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.
  • PerdrixP Online
    PerdrixP Online
    Perdrix
    wrote on last edited by Perdrix
    #1

    I have a QLabel called backgroundCalibration whose text I have set to "<a>Some text</a>"

    I did:

    ui->backgroundCalibration->setVisible(true);
    ui->backgroundCalibration->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
    ui->backgroundCalibration->setForegroundRole(QPalette::Link);
    
    void	StackingParameters::on_backgroundCalibration_linkActivated(const QString & str)
    {
    	str;
    	//
    	// Show the popup menu 
    	//
    	backgroundCalibrationMenu->exec(QCursor::pos());
    }
    
    

    When I display the Widget containing this label the text is displayed as "Some Text" and is displayed in Blue as I expected.

    However when I right-click left-click the text nothing happens! What crucial step did I miss?

    TIA
    David

    jsulmJ B 2 Replies Last reply
    0
    • PerdrixP Perdrix

      I have a QLabel called backgroundCalibration whose text I have set to "<a>Some text</a>"

      I did:

      ui->backgroundCalibration->setVisible(true);
      ui->backgroundCalibration->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
      ui->backgroundCalibration->setForegroundRole(QPalette::Link);
      
      void	StackingParameters::on_backgroundCalibration_linkActivated(const QString & str)
      {
      	str;
      	//
      	// Show the popup menu 
      	//
      	backgroundCalibrationMenu->exec(QCursor::pos());
      }
      
      

      When I display the Widget containing this label the text is displayed as "Some Text" and is displayed in Blue as I expected.

      However when I right-click left-click the text nothing happens! What crucial step did I miss?

      TIA
      David

      B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #12

      @Perdrix
      You cannot use "<a>Some text</a>" to expect a linkActivated signal.
      You must set some text as the link: "<a href="any text">Some text</a>", or the text won't even look like linked.

      JonBJ PerdrixP 2 Replies Last reply
      3
      • PerdrixP Perdrix

        I have a QLabel called backgroundCalibration whose text I have set to "<a>Some text</a>"

        I did:

        ui->backgroundCalibration->setVisible(true);
        ui->backgroundCalibration->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
        ui->backgroundCalibration->setForegroundRole(QPalette::Link);
        
        void	StackingParameters::on_backgroundCalibration_linkActivated(const QString & str)
        {
        	str;
        	//
        	// Show the popup menu 
        	//
        	backgroundCalibrationMenu->exec(QCursor::pos());
        }
        
        

        When I display the Widget containing this label the text is displayed as "Some Text" and is displayed in Blue as I expected.

        However when I right-click left-click the text nothing happens! What crucial step did I miss?

        TIA
        David

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Perdrix said in QLabel and right click:

        However when I right-click the text nothing happens!

        What do you expect to happen?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • PerdrixP Online
          PerdrixP Online
          Perdrix
          wrote on last edited by
          #3

          I expect the slot on_backgroundCalibration_linkActivated() to be driven.

          David

          jsulmJ 1 Reply Last reply
          0
          • PerdrixP Perdrix

            I expect the slot on_backgroundCalibration_linkActivated() to be driven.

            David

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Perdrix Shouldn't it happen on left mouse button click?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • PerdrixP Online
              PerdrixP Online
              Perdrix
              wrote on last edited by
              #5

              Sorry I meant when I LEFT click, nothing happens

              David (I'll edit the original text to correct that)

              jsulmJ 1 Reply Last reply
              0
              • PerdrixP Perdrix

                Sorry I meant when I LEFT click, nothing happens

                David (I'll edit the original text to correct that)

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Perdrix It seems like you're relying on the auto-connect feature, right? I mean you do not connect the signal to slot explicitly. You could try to connect by yourself to see whether it makes a difference.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • PerdrixP Online
                  PerdrixP Online
                  Perdrix
                  wrote on last edited by
                  #7

                  Yes, I'm using auto-connect and I don't get any warnings about Qt being unable to connect the signals to the slots (as I did when I originally tried to use on_backgroundCalibration_clicked() - that definitely got a complaint.

                  JonBJ jsulmJ 2 Replies Last reply
                  0
                  • PerdrixP Perdrix

                    Yes, I'm using auto-connect and I don't get any warnings about Qt being unable to connect the signals to the slots (as I did when I originally tried to use on_backgroundCalibration_clicked() - that definitely got a complaint.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #8

                    @Perdrix
                    Please at least put a qDebug()/breakpoint inside your slot to verify being called, just in case it is being called and you (somehow) can't see the menu!

                    1 Reply Last reply
                    0
                    • PerdrixP Perdrix

                      Yes, I'm using auto-connect and I don't get any warnings about Qt being unable to connect the signals to the slots (as I did when I originally tried to use on_backgroundCalibration_clicked() - that definitely got a complaint.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      @Perdrix The auto-connect feature is not that reliable. I would try with explicit connect. If it complains then post your connect call here and the error.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • PerdrixP Online
                        PerdrixP Online
                        Perdrix
                        wrote on last edited by Perdrix
                        #10

                        I added:

                        connect(ui->backgroundCalibration, SIGNAL(linkActivated(const Qstring &)), this, SLOT(on_backgroundCalibration_linkActivated()));
                        

                        to the ctor code just after the ui->SetupUI() call.

                        I have a breakpoint inside the slot code at the line that is intended to raise the menu, but it is never reached.

                        David

                        JonBJ 1 Reply Last reply
                        0
                        • PerdrixP Perdrix

                          I added:

                          connect(ui->backgroundCalibration, SIGNAL(linkActivated(const Qstring &)), this, SLOT(on_backgroundCalibration_linkActivated()));
                          

                          to the ctor code just after the ui->SetupUI() call.

                          I have a breakpoint inside the slot code at the line that is intended to raise the menu, but it is never reached.

                          David

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #11

                          @Perdrix
                          If that is a paste of your code, Qstring is mis-spelt. You would get help if that is not connecting the slot if you changed to new-style signal-slot syntax, which would benefit you in the long run.

                          1 Reply Last reply
                          3
                          • PerdrixP Perdrix

                            I have a QLabel called backgroundCalibration whose text I have set to "<a>Some text</a>"

                            I did:

                            ui->backgroundCalibration->setVisible(true);
                            ui->backgroundCalibration->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
                            ui->backgroundCalibration->setForegroundRole(QPalette::Link);
                            
                            void	StackingParameters::on_backgroundCalibration_linkActivated(const QString & str)
                            {
                            	str;
                            	//
                            	// Show the popup menu 
                            	//
                            	backgroundCalibrationMenu->exec(QCursor::pos());
                            }
                            
                            

                            When I display the Widget containing this label the text is displayed as "Some Text" and is displayed in Blue as I expected.

                            However when I right-click left-click the text nothing happens! What crucial step did I miss?

                            TIA
                            David

                            B Offline
                            B Offline
                            Bonnie
                            wrote on last edited by Bonnie
                            #12

                            @Perdrix
                            You cannot use "<a>Some text</a>" to expect a linkActivated signal.
                            You must set some text as the link: "<a href="any text">Some text</a>", or the text won't even look like linked.

                            JonBJ PerdrixP 2 Replies Last reply
                            3
                            • B Bonnie

                              @Perdrix
                              You cannot use "<a>Some text</a>" to expect a linkActivated signal.
                              You must set some text as the link: "<a href="any text">Some text</a>", or the text won't even look like linked.

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #13

                              @Bonnie
                              Good spot, as usual @Bonnie! Might be nice if the Qt docs reminded us of this somewhere, I didn't see much on what you had to do to a QLabel to make it a clickable link.

                              1 Reply Last reply
                              0
                              • PerdrixP Online
                                PerdrixP Online
                                Perdrix
                                wrote on last edited by
                                #14

                                Yes I spotted that just after I posted and fixed it.

                                So the code now reads:

                                connect(ui->backgroundCalibration, SIGNAL(linkActivated(const QString &)), this, SLOT(on_backgroundCalibration_linkActivated(const QString &)));
                                

                                and received no nastygrams about non-existent signals. Sadly the breakpoint is still not reached.

                                PS what's the new format for connecting the signals and slots? My book is strictly old school Qt4

                                David

                                jsulmJ 1 Reply Last reply
                                0
                                • PerdrixP Perdrix

                                  Yes I spotted that just after I posted and fixed it.

                                  So the code now reads:

                                  connect(ui->backgroundCalibration, SIGNAL(linkActivated(const QString &)), this, SLOT(on_backgroundCalibration_linkActivated(const QString &)));
                                  

                                  and received no nastygrams about non-existent signals. Sadly the breakpoint is still not reached.

                                  PS what's the new format for connecting the signals and slots? My book is strictly old school Qt4

                                  David

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #15

                                  @Perdrix Did you read what @Bonnie wrote?
                                  https://wiki.qt.io/New_Signal_Slot_Syntax/de

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • B Bonnie

                                    @Perdrix
                                    You cannot use "<a>Some text</a>" to expect a linkActivated signal.
                                    You must set some text as the link: "<a href="any text">Some text</a>", or the text won't even look like linked.

                                    PerdrixP Online
                                    PerdrixP Online
                                    Perdrix
                                    wrote on last edited by
                                    #16

                                    @Bonnie Silly question - why can't I just use <a>Text</a>? It is after all a valid minimal HTML anchor?

                                    I shall change the code immediately to use the format you suggested.

                                    D.

                                    JonBJ 1 Reply Last reply
                                    0
                                    • PerdrixP Perdrix

                                      @Bonnie Silly question - why can't I just use <a>Text</a>? It is after all a valid minimal HTML anchor?

                                      I shall change the code immediately to use the format you suggested.

                                      D.

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by JonB
                                      #17

                                      @Perdrix
                                      Because <a>Text</a> is not clickable in HTML, it just defines an anchor point user can jump to (via # on URL), see e.g. https://stackoverflow.com/questions/10510191/valid-to-use-a-anchor-tag-without-href-attribute.

                                      1 Reply Last reply
                                      1
                                      • PerdrixP Online
                                        PerdrixP Online
                                        Perdrix
                                        wrote on last edited by
                                        #18

                                        @Bonnie said in QLabel and right click:

                                        href="any text"

                                        Thanks Bonnie - that solved it ...

                                        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