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. connect button to stackWidget and radioButton to comboBox
Forum Updated to NodeBB v4.3 + New Features

connect button to stackWidget and radioButton to comboBox

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.6k 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.
  • I Offline
    I Offline
    isan
    wrote on last edited by isan
    #1

    I want to connect pushButton to stackWidget index I used

    connect(ui->user, SIGNAL(clicked(bool)), ui->stackedWidget,SLOT(setCurrentIndex(int)));
    

    It is not complete and it does not work

    And to connect radioButton to the comboBox (if radioButton was hit, comboBox would be enabled) I used

    connect(ui->radioButton_co,SIGNAL(clicked()),ui->comboBox_co,SLOT(setEnabled(bool)));
    

    It also not complete and it does not work
    How should I do this without defining any function?

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

      Hi
      connect(ui->user, SIGNAL(clicked(bool)), ui->stackedWidget,SLOT(setCurrentIndex(int)));

      Can never work as clicked can maximum send a bool and
      setCurrentIndex expects and int that tells what index to go to.

      What do u try to make it do with one button ?

      for combobox
      connect(ui->radioButton_co,SIGNAL(clicked(bool)),ui->comboBox_co,SLOT(setEnabled(bool)));
      should work.
      But not sure it works as you want as radio buttons normally comes in a group.
      If you just have 1 radiobutton, its not possible to unselect it again.

      If just to enable combo, then QCheckbox might be better.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        isan
        wrote on last edited by
        #3

        I did this to change the page

        void Healthy::on_user_clicked()
        {
            ui->stackedWidget->setCurrentIndex(5);
        }
        

        But I want to use a connection to do this
        comboBox is disabled for the first time

        ui->comboBox_co->setDisabled(1);
        

        I used QCheckBox, but when checking QCheckBox ,the comboBox is not enabled

        connect(ui->checkBox_co,SIGNAL(clicked()),ui->comboBox_co,SLOT(setEnabled(bool)));
        

        when I run the program I get this

        QObject::connect: Incompatible sender/receiver arguments
                QCheckBox::clicked() --> QComboBox::setEnabled(bool)
        
        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          But dont u need to slots like
          nextPage and prevPage ?
          to go back and forth. You can use lambdas for compact design.

          you forgot the parameter type
          connect(ui->checkBox_co,SIGNAL(clicked(bool)),ui->comboBox_co,SLOT(setEnabled(bool)));
          also connects return true/false so u can spot when you have made error.

          1 Reply Last reply
          1
          • I Offline
            I Offline
            isan
            wrote on last edited by isan
            #5
            connect(ui->checkBox_co,SIGNAL(clicked(bool)),ui->comboBox_co,SLOT(setEnabled(bool)));
            

            And I use this for change page

            connect(ui->user, &QAbstractButton::clicked, [=](bool b){ui->stackedWidget->setCurrentIndex(5);});
            

            it work thanks to u

            mrjjM 1 Reply Last reply
            0
            • I isan
              connect(ui->checkBox_co,SIGNAL(clicked(bool)),ui->comboBox_co,SLOT(setEnabled(bool)));
              

              And I use this for change page

              connect(ui->user, &QAbstractButton::clicked, [=](bool b){ui->stackedWidget->setCurrentIndex(5);});
              

              it work thanks to u

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @isan
              Ok super.
              So you just need button to go exact page. and not navigate back and forth.

              I 1 Reply Last reply
              0
              • mrjjM mrjj

                @isan
                Ok super.
                So you just need button to go exact page. and not navigate back and forth.

                I Offline
                I Offline
                isan
                wrote on last edited by
                #7

                @mrjj said in connect button to stackWidget and radioButton to comboBox:

                So you just need button to go exact page. and not navigate back and forth.

                at this time ,yes

                1 Reply Last reply
                1

                • Login

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