Used to it qt3 's friends are using qt4 There must be some discomfort , Including building the interface , The use of some classes , There are some differences , Generally speaking Qt4 In the programming way, the design is more reasonable , Because it makes the interface code and operation code complete “ quarantine ” open an account with , In this way, we can avoid the embarrassing situation that we will rewrite the operation code when we modify the interface and then compile .qt4 In addition to optimizing the interface settings , Some classes are also simplified . Like the original Qt3 above QButtonGroup class , stay qt4 Of designer It doesn't show up . Just keep the original qt3 Of ButtonGroup. Right? qt4 There's no one up there QButtonGroup What about the class , Of course not . stay qt4 Of assistant It's described above QButtonGroup When he said :“
QButtonGroup provides an abstract container into which button widgets can be
placed. It does not provide a visual representation of this container (see 
QGroupBox for a container widget), but instead manages the states of each of
the buttons in the group”. It is mentioned that QButtonGroup Provides a virtual container for placing key controls , But it's not a visual container . It means
QButtonGroup stay qt4 Becomes an abstract class . But you can also manage the buttons as before . The usage is as follows :

       The first is to declare a QButtonGroup Class :QButtonGroup *buttonGroup;

       Then allocate space to the pointer object in the initialization or constructor :buttonGroup = new QButtonGroup;

       And then you can use it addButton() Function to add the key you want to place :

            buttonGroup->addButton( ui.pushButton0, 0 );
            buttonGroup->addButton( ui.pushButton1, 1 );
            buttonGroup->addButton( ui.pushButton2, 2 );
             buttonGroup->addButton( ui.pushButton3, 3 );
            buttonGroup->addButton( ui.pushButton4, 4 );
            buttonGroup->addButton( ui.pushButton5, 5 );
            buttonGroup->addButton( ui.pushButton6, 6 );
           buttonGroup->addButton( ui.pushButton7, 7 );
            buttonGroup->addButton( ui.pushButton8, 8 );
             buttonGroup->addButton( ui.pushButton9, 9 );

     In this way, you can match the desired button with its corresponding one ID The numbers correspond , Every time you click a key QButtonGroup Metropolitan signal buttonClicked (int
ID) launch , By judgment ID The slot is connected to it , The key can be judged . for example :

        connect( buttonGroup, SIGNAL(buttonClicked (int)), this,
SLOT(buttonJudge(int)) );// Connecting signals and slots

Finally, it is OK to judge the key in the slot function . Of course, the slot function should be declared in advance .

void IPhone::buttonJudge(int buttonID)
{
    if((modeFlag == defaultMode) || (modeFlag == hangupMode) || (modeFlag ==
inputMode))
{
   resetFont(1);
   if(modeFlag != inputMode)
    ui.lineEdit->clear();
   modeFlag = inputMode;
   switch (buttonID)
   {
      case 0: ui.lineEdit->insert("0"); break;
      case 1: ui.lineEdit->insert("1"); break;
      case 2: ui.lineEdit->insert("2"); break;
      case 3: ui.lineEdit->insert("3"); break;
      case 4: ui.lineEdit->insert("4"); break;
      case 5: ui.lineEdit->insert("5"); break;
      case 6: ui.lineEdit->insert("6"); break;
      case 7: ui.lineEdit->insert("7"); break;
      case 8: ui.lineEdit->insert("8"); break;
      case 9: ui.lineEdit->insert("9"); break;
    case 10: ui.lineEdit->insert("."); break;
    case 11: ui.lineEdit->insert("#"); break;
    default: break;
   }
}
}

In this way, we can realize simple key discrimination .

Technology
©2019-2020 Toolsou All rights reserved,
One is called “ Asking for the train ” A small village Finally got the train Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type I've been drinking soft water for three years ? What is the use of soft water and water softener You don't know ——HarmonyOS Talking about uni-app Page value transfer problem JavaScript Medium Call and ApplySparkSQL Achieve partition overlay write Character recognition technology of vehicle license plate based on Neural Network