开发者

How to set auto=repeat on a qaction in a qtoolbar?

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

The problem is that the instances are cre开发者_运维知识库ated 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


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) {
        ...
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜