PDA

View Full Version : Why there are always dashed-line rectangle on QToolButton?



FinderCheng
22nd October 2009, 14:57
I added a QToolButton onto a QToolBar. But the first button always has the dashed line ractangle around it. Even if I click other button, the first button still has that rectangle. I don't know how to remove it. Here I set each QToolButton as following code:


action = new QAction(this);
action->setIcon(icon);
action->setCheckable(true);
actionGroup->addAction(action);

And then I create the QToolButton:


QToolButton * createToolButton(QAction *action)
{
QToolButton *button = new QToolButton;
button->setDefaultAction(action);
button->setAutoRaise(true);
return button;
}
// ...
QToolButton *button = createToolButton(action);
layout->addWidget(button , 0, 0, 1, 1);
// other butttons

Please help me. Thank you all!

wysota
22nd October 2009, 17:29
This is called "keyboard focus". Anyway, you shouldn't create tool buttons for actions yourself. Just add the action to a toolbar and a tool button will be created for you.

FinderCheng
23rd October 2009, 01:37
Yeah, I know I could add QAction onto QToolBar directly. But I want to have a grid-like tool bar with two columns. I don't know how to implement it so I added a QWidget with QGridLayout and then added this widget into tool bar therefore I have to create QToolButton myself.
Then how to remove this key focus or how to add actions into a tool bar with mutil-columns?

wysota
23rd October 2009, 09:55
You can try setting the focus policy for each of the buttons to NoFocus.

FinderCheng
23rd October 2009, 16:36
Thanks! It works! Hope there is no side effects... :-)

axeljaeger
25th October 2009, 00:56
The side effect is that you disabled keyboard navigation.