PDA

View Full Version : Drop down menu in qt4?



cbarmpar
25th September 2008, 20:37
Hi all,

I have a lineEdit widget and I am trying to make a drop down menu similar to the one that firefox has on the top right(where google search is).

In qt3 I found a class QPopupMenu. But this class is not included in qt4. Is there anything similar for qt4?

Can you please provide a sample code to demonstrate that?

Many thanks in advance.

spirit
25th September 2008, 20:44
I think this hepls you QToolButton (http://doc.trolltech.com/4.4/qtoolbutton.html#setMenu)

cbarmpar
25th September 2008, 20:52
Thank you for the reply.

What i actually want is to pop up a menu containing the results of a query made from the text box.Very similar to what firefox does in the top right box

spirit
25th September 2008, 21:00
so, you need to show popup when you input data in QLineEdit, right?

spirit
25th September 2008, 21:03
see this calss QCompleter (http://doc.trolltech.com/4.4/qcompleter.html)

cbarmpar
26th September 2008, 14:35
I have one more question.

If i want to add a custome message in this pop up box say for example:
"possible matches":
and then the matches found how can i do that?

Because with completer a pop up window shows only with the completion options.

regards.

spirit
26th September 2008, 14:41
m... I'm not sure that I understand what you mean. :)

caduel
26th September 2008, 15:02
a bit of a hack:

Set QCompleter::setPopup with a QTreeView and have the model provide your "text"
in its headerData() function as caption of the first column.

(Haven't tried it. Please post if it works.)

cbarmpar
26th September 2008, 15:17
caduel thats a good idea.

I will try it now.

But even if that works it doesnt give you the flexibility that i would like.
What about if i would like to provide more than one custom message apart from the completion options. For example, I want my cutom message in the first line then have some completion options and then another custom message in the fifth line. This is not possible with the header technique that you suggesting I think.

I will try it and let you know.
Regards