A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

1.多重信号和槽的配对设置

void TableWidget::connetSlot()
{
for (int i = 0 ;i<m_actions.size() ;i++)
{
QObject ::connect(m_actions,SIGNAL(triggered()),this,SLOT(onTriggerded()));

}
}

void TableWidget::onTriggerded()
{
QObject *onSender = QObject :: sender() ;
QAction * onAction = dynamic_cast<QAction*>(onSender)  ;
int index = m_actions.indexOf(onAction) ;
if (-1 == index )
{
return ;
}
ActionName actTemp = ActionName(index) ;
//quit()是application , close是widget
switch(actTemp)
{
//文件菜单功能
case  actNew:newfunction();break;
case actOpen:openFunction() ;break ;
case actSave :actSaveFunction();break ;
case actSaveAs:actSaveAsFunction();break ;
case actExit :qApp->quit() ;break;
//编辑栏菜单功能
case actCut : actCutFunction() ;break ;
case actCopy :actCopyFunction() ;break ;
case actPaste : actPasteFunctinon() ;break;
case actDelete : actDeleteFunction() ;break;
case actFont : actFontFunction() ;break;
case actBackGround :actBackGroundFunction(); break;
//帮助菜单
case actQtAbout : actQtAboutFunction() ;break;
case actHelp : actHelpFunction() ;break;
default: break;
}
}


状态栏信号槽的链接

bool b = QObject :: connect(
tableWidget,
SIGNAL(currentItemChanged ( QTableWidgetItem * , QTableWidgetItem*  ))
,this,
SLOT(updateLocation ( QTableWidgetItem * , QTableWidgetItem*  ))
);


void TableWidget::updateLocation(QTableWidgetItem *item ,QTableWidgetItem*)
{
if (item && item == tableWidget->currentItem())
{
QString n = QString ::number(item->row()+1,10) ;
QString m = QString (item->column()+'A') ;
curLocation->setText(tr("cell : (第%1行 第%2列)").arg(n ).arg(m));
QString txt = item->text() ;
curItem->setText(txt) ;
}
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马