Russian Qt Forum

Qt => Пользовательский интерфейс (GUI) => Тема начата: Андрей80 от Май 03, 2010, 18:24



Название: Как в QTextEdit добавить элемент в контекстное меню?
Отправлено: Андрей80 от Май 03, 2010, 18:24
Здравствуйте.
По умолчанию экземпляр QtextEdit имеет стандартное контекстное меню
undo
redo
cut
copy
paste
delete
selectAll

Возможно ли как то добавить новый элемент в это меню?
(Ожидал найти что-то вроде
QMenu* QTextEdit::contextMenu()
но его нет. )
Заранее спасибо за помощь


Название: Re: Как в QTextEdit добавить элемент в контекстное меню?
Отправлено: MoPDoBoPoT от Май 03, 2010, 19:14
Цитата: QtAssistant
void QTextEdit::contextMenuEvent ( QContextMenuEvent * event )   [virtual protected]

Shows the standard context menu created with createStandardContextMenu().

If you do not want the text edit to have a context menu, you can set its contextMenuPolicy to Qt::NoContextMenu. If you want to customize the context menu, reimplement this function. If you want to extend the standard context menu, reimplement this function, call createStandardContextMenu() and extend the menu returned.

Information about the event is passed in the event object.
Код:
 void MyTextEdit::contextMenuEvent(QContextMenuEvent *event)
 {
     QMenu *menu = createStandardContextMenu();
     menu->addAction(tr("My Menu Item"));
     //...
     menu->exec(event->globalPos());
     delete menu;
 }