0

我已经将一些带有循环的 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);

如何将信号连接到将从按钮执行命令的插槽?顺便说一句,命令设置为工具提示。

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

4

1 回答 1

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 &)));
于 2012-04-20T13:11:17.570 回答