[Interest] QMenu size

Bo Thorsen bo at vikingsoft.eu
Thu Nov 17 10:23:46 CET 2016


Hi Joshua,

Den 15-11-2016 kl. 17:28 skrev Joshua Grauman:
> Thanks! These are great ideas. It's not about making it work like
> another system, but it is a unique requirement having to do with
> recording the screen...

Typical, you actually managed to find a good reason for doing this :)

> If you don't mind, could you clarify a bit what you mean with a couple
> of your suggestions?
>
>> - Work with the width for height tricks
>
> What does this mean?

You could use the heightForWidth() to have some control over the size of 
it. Wouldn't be my first choice here and I'm not even sure where I would 
take it. But I mentioned it because you said you had to control the size 
of it, and this is one of the lesser known tricks that I sometimes use 
to do it.

>> - 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
>
> I understand the first two of these, but where would I implement a 0
> time single shot?

The timer is in the class that opens the popup menu. If you have a 
method where you set up the menu, you can do something like this:

QMenu popup;
// set up the menu here
QTimer::singleShot(0, [=]() {
   // Handle popup size here
}
popup.exec();

Bo.

> On Tue, 15 Nov 2016, Bo Thorsen wrote:
>
>> 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
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>


Bo Thorsen,
Director, Viking Software.

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



More information about the Interest mailing list