2012-04-13 31 views
0
從CommanLinkBut​​tons連接各種信號

我已經把一些CommandLinkBut​​tons一些環插入一個QTableWidget的:從QTableWidget的

QCommandLinkButton *MysticalButton = new QCommandLinkButton; 

QueryReturn = ModHandling->ModuleXML("attribute",ModuleList.at(iMod),"Settings","Icon"); 
QIcon Icon(QueryReturn); 
QSize IconSize; 
IconSize.scale(48, 48, Qt::KeepAspectRatio); 
MysticalButton->setIconSize(IconSize); 
MysticalButton->setIcon(Icon); 

QueryReturn = ModHandling->ModuleXML("search", ModuleList.at(iMod), "Title"); 
MysticalButton->setText(QueryReturn); 

QueryReturn = ModHandling->ModuleXML("search", ModuleList.at(iMod), "Description"); 
MysticalButton->setStatusTip(QueryReturn); 

// I use the Tooltip to get the Command of this Button: 
QueryReturn = ModHandling->ModuleXML("search", ModuleList.at(iMod), "Exec"); 
MysticalButton->setToolTip(QueryReturn); 

ui->tableWidget_Main->setCellWidget(iRow, iCol, MysticalButton); 

我如何把信號連接到將從按鈕執行命令插槽?該命令設置爲工具提示btw。

如果你知道一個更好的方式來設置命令按鈕,那麼請讓我知道(=

回答

0

看看QSignalMapper,或者乾脆在你點擊插槽使用qobject_cast<QCommandLinkButton *>(sender())

QSignalMapper * signalMapper = new QSignalMapper(this); 

QCommandLinkButton *MysticalButton = new QCommandLinkButton; 

QueryReturn = ModHandling->ModuleXML("attribute",ModuleList.at(iMod),"Settings","Icon"); 
QIcon Icon(QueryReturn); 
QSize IconSize; 
IconSize.scale(48, 48, Qt::KeepAspectRatio); 
MysticalButton->setIconSize(IconSize); 
MysticalButton->setIcon(Icon); 

QueryReturn = ModHandling->ModuleXML("search", ModuleList.at(iMod), "Title"); 
MysticalButton->setText(QueryReturn); 

QueryReturn = ModHandling->ModuleXML("search", ModuleList.at(iMod), "Description"); 
MysticalButton->setStatusTip(QueryReturn); 

// I use the Tooltip to get the Command of this Button: 
QueryReturn = ModHandling->ModuleXML("search", ModuleList.at(iMod), "Exec"); 
MysticalButton->setToolTip(QueryReturn); 

ui->tableWidget_Main->setCellWidget(iRow, iCol, MysticalButton); 

connect(MysticalButton, SIGNAL(clicked()), signalMapper, SLOT(map())); 
signalMapper->setMapping(MysticalButton, QueryReturn); 


connect(signalMapper, SIGNAL(mapped(const QString &)), 
     this, SIGNAL(executeCommand(const QString &)));