Frage

I've implemented a dialog with two customized text-editor inside(Two editor objects with same class) This custom widget is an inherited class from QWidget and it has two widgets inside, one is a actions-tool-bar and second is a QTextEdit. I set some shortcuts to this custom widget for some actions like 'Make text Bold', 'Make text Italic', so on.

here is a picture of these widgets inside of my dialog:

Two custom Text-Edit inside a dialog

So far every thing is ok. But, when I press Ctrl+B for example, I got this error message:

QAction::eventFilter: Ambiguous shortcut overload: Ctrl+B

setting the shortcut context to WidgetWithChildrenShortcut won't help me to disambiguate shortcuts.

anyone has any other idea?

War es hilfreich?

Lösung

Finally, I found the solution. My editor was inherited from qtextedit. I add this lines to each action, and it works now!

void MyEditor::addActionToToolbar(QAction *a)
{
    a->setShortcutContext(Qt::WidgetWithChildrenShortcut);
    addAction(a);

    QToolButton* btn = new QToolButton(this);
    btn->setDefaultAction( a );
    btn->setFocusPolicy(Qt::NoFocus);
    btn->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
    btn->setIconSize(QSize(16,16));

    toolBar->addWidget(btn);    
}

Andere Tipps

You can have two toolbars, but they should use an action that acts on the currently focused editor, and you want only one QAction to exist, not multiple of them. In spite of one QAction you can have multiple buttons linked to it.

Most likely your editor widgets behave inappropriately by defining their own actions. They shouldn't do that.

you need to install an event filter, there is a nice example in documentation.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top