tags:

views:

72

answers:

2

Hi,

I'd like to use the autorepeat feature of the QToolButton class.

The problem is that the instances are created automatically when using QToolBar::addAction() and I can't find a way to reach them: QToolBar::widgetForAction() doesn't seem to work in that case (always returns NULL).

Any ideas? Thanks

A: 

There seem to be no simple way. The best I found is to use QObject::findChldren :

foreach(QToolButton* pButton, pToolBar->findChildren<QToolButton*>()) {

 if (pButton->defaultAction() == pTheActionIWant) {
  ...
 }
}
gregseth
A: 

In fact, in my case doesn't return NULL, maybe you are doing something different. My code is as follows:

QToolButton* button = dynamic_cast<QToolButton*>(
    ui.toolBar->widgetForAction(ui.action));

For me it works as intended.... Maybe you aren't casting? This method returns a QWidget* and my compiler issues and error if I don't cast.

FYI, I'm using Visual Studio 2005 with Qt 4.6.

fvila
I'm using Qt 4.5, they may have fixed it since.
gregseth