[Interest] QMenu size

Bo Thorsen bo at vikingsoft.eu
Tue Nov 15 14:59:19 CET 2016


Den 08-11-2016 kl. 23:05 skrev Joshua Grauman:
> Hello all,
>
> I am wondering if there is a way to customize the size of a QMenu used
> as a context menu. I have it so that when I right click, a popup menu
> comes up. But I would like it so the QMenu doesn't ever go outside of
> the window it is clicked in. Right now, if you click near the bottom,
> the QMenu drops below my app. Or if I have a QMenu with a lot of items,
> it breaks it up into two columns worth of items, is there a way to make
> that more (for a wider and less tall sub-QMenu)? Thanks for any thoughts.

This sounds to me like you are trying to force Qt to do something that 
some other system used to do?

I have a lot of requests from customers and I always try to make them 
accept that the default way of doing things are there for a number of 
reasons and they should accept it the it is. So, my advice is to stop 
thinking about this. Or make the guy deciding this stop thinking about it :)

However, if you can't do that, you always have options. Here are a set 
of some of the things I would try:

- Set the maximum height on the QMenu

- Work with the width for height tricks

- You can move the menu after it appears with either a reimplementation 
in the resizeEvent, eventFilter on resize or other events, or using 0 
time single shot timer

- There are probably a bunch of possible hacks that might work in the 
area of proxy QStyle subclasses

I hope this helps.

Bo Thorsen,
Director, Viking Software.

-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu



More information about the Interest mailing list