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. Label change and corrosponding action on pushbutton
Forum Updated to NodeBB v4.3 + New Features

Label change and corrosponding action on pushbutton

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 866 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.
  • A Offline
    A Offline
    anuj nogja
    wrote on last edited by
    #1

    I want to add a pushbutton which can initiate or terminate the data processing. Initially label on button should be "initiate"-clicking on it starts prcessing. As this button is clicked label should change to " terminate". If terminate is clicked- it should stop processing of data and label on button should change to "initiate"....and so on.

    Kindly suggest the solution..
    Regards,
    Anuj

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      How do you interrupt the processing ?
      Are you using threads or do you want to call a function repeatedly ?
      If you are think about any kind of loop. that's not it. long lasting loops don't play well with GUI :)

      Can you tell about bit more about the processing?
      You could use push buttons checkbox feature.
      so when "down" it starts a time and in timers slot perform processing.
      if unchecked, it calls timer stop.

      A 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        How do you interrupt the processing ?
        Are you using threads or do you want to call a function repeatedly ?
        If you are think about any kind of loop. that's not it. long lasting loops don't play well with GUI :)

        Can you tell about bit more about the processing?
        You could use push buttons checkbox feature.
        so when "down" it starts a time and in timers slot perform processing.
        if unchecked, it calls timer stop.

        A Offline
        A Offline
        anuj nogja
        wrote on last edited by
        #3

        @mrjj Hi,
        Here processing of data is reading data from file and plotting it. When clicked on initiate, starts plotting and changes the label to terminate. When terminate on same button is clicked, plotting is stopped and label of same button changes to initiate.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          Not super elegant but it works

          connect(button,&QPushButton::clicked,this,[=]()->void{
          const QString initiateText = tr("initiate");
          if(button->text()==initiateText)
          button->setText(tr("terminate"));
          else
          button->setText(initiateText);
          });
          

          EDIT:

          See page 171 of C++ GUI Programming with Qt 4

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2

          • Login

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