YAPPO
YAPPO

Reputation: 173

Qt Popup as a completer window

I need to make some kind of popup window that contains propositions to complete sentences in text editor (QTextPlainEdit). This window needs to be on top of all windows of this application. Also this popup mustn't interrupt typing in the text editor when it appears. I tried different types of flags for QWidget that implements this completer but all I have got is that this completer window is placed above all windows of OS (even if this application is not active) or it interrupts typing in the text editor and makes main window not active any time it appears.

What flags should I use for completer widget?

Upvotes: 2

Views: 3568

Answers (2)

romaingz
romaingz

Reputation: 431

You could try to use QWidget::setWindowFlags(Qt::Window | Qt::FramelessWindowHint). Otherwise you could use a customized version of Qt::Popup, by overriding the automatic closing behavior.

You could also try this: if you set the QTextPlainEdit's parent as the completer's parent it should do what you want, provided that the parent does not have a layout (otherwise it will not "float").

Upvotes: 1

mooware
mooware

Reputation: 1762

The Qt docs contain an example that implements a google-based auto-completer widget, here: http://qt-project.org/doc/qt-4.8/network-googlesuggest.html.

As far as I can tell, they do two things that might be relevant to your situation. One is the flags they set on the popup widget:

popup = new QTreeWidget;
popup->setWindowFlags(Qt::Popup);
popup->setFocusPolicy(Qt::NoFocus);
popup->setFocusProxy(parent);

The other is a custom event filter on the popup widget, which forwards most keypress-events to the editor widget, and closes the auto-completer on Enter or Escape.

Upvotes: 1

Related Questions