从QTableWidget连接来自CommanLinkBut​​tons的各种信号

时间:2012-04-13 19:54:50

标签: qt4 qtablewidget

我将一些带有一些循环的CommandLinkBut​​tons放入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);

如何将信号连接到将从按钮执行命令的插槽?命令设置为ToolTip btw。

如果您知道将命令设置为按钮的更好方法,请告诉我(=

1 个答案:

答案 0 :(得分: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 &)));