PDA

View Full Version : Creating an Intellisense style window or dialog



qtnewbie6019
7th March 2013, 21:33
Hi I am trying to learn pyqt by writing my own texteditor, using pyQT one of the things i want to have is intellisense/word suggestions. i.e so that as you type in the text editor it offers you suggestions of words that would be suitable. I have a list of words, and i can already generate a list of suggestions. My difficulty is presenting it, I am unable to bring up a window/dialog at the cursor location which shows a list of possible words. So far I have succesfully got QMenu to work, but it is limited as in it has no scrollbars and can only display a limited number of suggestions. I tried QListWidget, but this displayed a popup window(complete with max,min buttons) this just isn't right, though it did allow me to have scrollbars. I would like to know what object I should use to display suggestions to a user at the cursor location just like one sees in any good IDE. This is what I am trying to do
8801

wysota
7th March 2013, 23:02
The widget you need to use is QListView or QListWidget. You need to position it manually and handle its key events -- most likely by installing an event filter on it and forwarding some events to the text editor or eating them directly in the view. In doubt you can see how QtCreator does it for its own completion support. All in all it is not that complicated if you understand how Qt works.

ChrisW67
7th March 2013, 23:03
You can (generally) turn off the window frame that you see on the QListWidget: See QWidget::setWindowFlags() and Qt::FramelessWindowHint.

You might want to take a good look at the Custom Completer Example and how it makes use of QCompleter.