Hi there,
while developing a small plugin for a friend of mine, he asked me if I wasn't able to add a Button to the Toolbar in the Teamspeak-Client instead of having to use Plugin-Commands or assigning Hotkeys to Plugin-Commands.
I remembered having read a Thread about getting access to the QWidgets, so I started with compiling a QT 4.7.2 (the Version the TS-Client uses) with msvc2010 and followed the instructions given in the mentioned post.
The first thing I noticed was that Teamspeak seems to derive QToolbar in a class named "ImprovedToolBar" and uses that one. Because I have no headers defining the improvedtoolbar, I used AddAction on the Toolbar dynamic_casted to a QToolbar. While this does add a Button with the specified Image and Text, I have not been able to make QT call my functions when the user clicks the button.
Since I'm not an Expert in QT and its Signal/Slot-System, I don't know if the problem lies with me (for using it somehow wrong) or with the functions not being virtual and every click being intercepted by the ImprovedToolBar.
This is the (non-working) Button I managed to add: 
TL;DR: I try to add a custom button to the TS3-Toolbar, but I don't manage to react on clicks.
I get the reference to the Toolbar by iterating on QApplication::allWidgets
Code:
foreach(QWidget* pWidget, QApplication::allWidgets())
{
QToolBar* toolbar = dynamic_cast<QToolBar*>(pWidget);
if(toolbar != 0)
{
_toolbar = toolbar; //Declared in header: QToolBar* _toolbar;
break;
}
}
This is how I add the Button:
Code:
QString text = "Testtext";
QIcon img = QIcon("Testimg.png");
QAction* toolbarAction = _toolbar->addAction(qimg, qtext);
Btn_Info_Container* container = new Btn_Info_Container(toolbarAction);
I left out the code for caching the Container-Object and removing the action from the Toolbar before unloading the plugin for brevity.
This is the Container class as defined in its header:
Code:
class Btn_Info_Container : public QObject
{
public:
Btn_Info_Container(QAction* action);
~Btn_Info_Container();
QAction* action;
public slots:
void trigger();
};
And here are the Constructor and the Slot:
Code:
Btn_Info_Container::Btn_Info_Container(QAction* action)
{
this->action = action;
connect((QObject*)action, SIGNAL(triggered()), this, SLOT(trigger()));
}
void Btn_Info_Container::trigger()
{
std::cout << "Click!!";//This is never called
}
I also tried to bind the Toolbar's "action_triggered" event, but that does not get called, too.
How to react on user clicks on my button?
Another method that could work would be to use the QToolBar.addWidget-Method instead of addAction (I haven't tried that one so far, will do that tomorrow), but what Widget-class do I need to preserve the look (including the current theme)? Is a QPushButton the way to go?
EDIT: I've tried adding a QPushButton, but instead of solving the problem (it does not trigger my slot when clicked), it just looks very strange. Further, I discovered that typos in the SLOT- or SIGNAL-keywords don't produce compiler-errors, even though I thought that the type-safety was supposed to be the main benefit of the whole Signal/Slot-System over callbacks??
EDIT2: I've even tried to subclass QAction and override it's virtual event () function to write something to the console, but still no luck. I think that the Problem is with the "improvedToolbar". I'll try to add my button to any other, QT-default-classes based widget to see if I'm right.
Any help is appreciated.