Qt: How to implement QDialogButtonBox with QSignalMapper for non-standard button ??

后端 未结 2 1996
萌比男神i
萌比男神i 2021-01-21 21:10

I have a QDialogButtonBox with All Standard Button and Non Standard Buttons (QPushbutton added to create Non-Standard Buttons).

I can implement SignalMapper saperately f

2条回答
  •  臣服心动
    2021-01-21 21:40

    QSignalMapper can map a QObject and a integer. So you can map your non-standardButton with its role and create a slot that takes in parameter a role:

    For example:

    void Widget::initMap() {
         QPushButton* buttonReset = new QPushButton( "Reset" );
         signalMapper = new QSignalMapper(this);
         connect(buttonReset, SIGNAL(clicked()), signalMapper, SLOT(map()));
         signalMapper->setMapping(button, QDialogButtonBox::ResetRole);
         connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(slot(int)));
    }
    
    void Widget::slot( int role) {
        if ( role == QDialogButtonBox::ResetRole ) {
            reset();
        } else if ( QDialogButtonBox::Apply ) {
            apply();
        }
    }
    

提交回复
热议问题