0

I've put some CommandLinkButtons with some loops into a 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);

How do i connect a Signal to a Slot which will execute the Command from the Button? The Command is set as ToolTip btw.

If you know a better way to set the command to the button then please let me know (=

yokmp
  • 145
  • 2
  • 10

1 Answers1

0

Take a look at QSignalMapper, or simply use qobject_cast<QCommandLinkButton *>(sender()) in your clicked slot

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 &)));
Kamil Klimek
  • 12,884
  • 2
  • 43
  • 58