Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, March 2008
Title in QMenu


Message 1 in thread

Hi.

Is there a simple way to display a title on top of a QMenu?

I would like to create e context menu (that popup on right-click) with a title. I see that QMenu can have a title (I can pass a title in the constructor or call setTitle()), but this string is never displayed.

I also tried to subclass QMenu and add a QAction as title, but I'm not able to draw it in a different way in comparison of the others actions. Setting the font of the action doesn't work. I've also tried to implement the method initStyleOption(QStyleOptionMenuItem *option, const QAction *action) in this way but doesn't work. Debugging I see that this method is never called.


void TitleMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const
{
	if(action == titleAction)
	{
		QFont f;
		f.setBold(true);
		f.setPointSize(10);
		option->font = f;
	}
	else
		QMenu::initStyleOption(option, action);
}


Moreover I want that the title of a menu have also a different backgound.

Is it all possible?

Thanks

Fabio.

--
 [ signature omitted ] 

Message 2 in thread

On Monday 17 March 2008 09:35:59 fabiodago@xxxxxxxxx wrote:
> I've also tried to implement the
> method initStyleOption(QStyleOptionMenuItem *option, const QAction *action)
> in this way but doesn't work. Debugging I see that this method is never
> called.
it's not virtual. no chance. :(
> Moreover I want that the title of a menu have also a different backgound.
> Is it all possible?
yeah.  Just keep in mind that you are breaking desktop integration and maybe  
style awareness.
QMenu is a Qwidget, so you can reimplment paintEvent and move the actions down 
a litle to display your title.Transformation might do the trick. also 
reimplemt the sizehint to reflect your title size.

-- 
 [ signature omitted ] 

Message 3 in thread

Or you can insert "dummy" QAction and set different font to it
(setFont) and make it disabled. Then it could look as a title. Still,
you may have to alter the paintEvent to draw the "title" a bit
differently (with another style/color/etc..).

Martin Petricek

On 3/17/08, Arvid Ephraim Picciani <aep@xxxxxxxxxxxxxxx> wrote:
> On Monday 17 March 2008 09:35:59 fabiodago@xxxxxxxxx wrote:
>  > I've also tried to implement the
>  > method initStyleOption(QStyleOptionMenuItem *option, const QAction *action)
>  > in this way but doesn't work. Debugging I see that this method is never
>  > called.
>
> it's not virtual. no chance. :(
>
> > Moreover I want that the title of a menu have also a different backgound.
>  > Is it all possible?
>
> yeah.  Just keep in mind that you are breaking desktop integration and maybe
>  style awareness.
>  QMenu is a Qwidget, so you can reimplment paintEvent and move the actions down
>  a litle to display your title.Transformation might do the trick. also
>  reimplemt the sizehint to reflect your title size.
>
>  --
>  best regards/Mit freundlichen Grüßen
>
> Arvid Ephraim Picciani
>
>
>  --
>  To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>  List archive and information: http://lists.trolltech.com/qt-interest/
>
>

--
 [ signature omitted ] 

Message 4 in thread

---------- Initial Header -----------

From      : "Arvid Ephraim Picciani" aep@xxxxxxxxxxxxxxx
To          : qt-interest@xxxxxxxxxxxxx
Cc          :
Date      : Mon, 17 Mar 2008 19:13:55 +0100
Subject : Re: Title in QMenu







> On Monday 17 March 2008 09:35:59 fabiodago@xxxxxxxxx wrote:
> > I've also tried to implement the
> > method initStyleOption(QStyleOptionMenuItem *option, const QAction *action)
> > in this way but doesn't work. Debugging I see that this method is never
> > called.
> it's not virtual. no chance. :(
> > Moreover I want that the title of a menu have also a different backgound.
> > Is it all possible?
> yeah.  Just keep in mind that you are breaking desktop integration and maybe
> style awareness.
> QMenu is a Qwidget, so you can reimplment paintEvent and move the actions down
> a litle to display your title.Transformation might do the trick. also
> reimplemt the sizehint to reflect your title size.
>
> --
> best regards/Mit freundlichen Grüßen
> Arvid Ephraim Picciani
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

It's a good idea. But what do you mean with "Transformation might do the trick"? I don't know how to move the actions down...

This is a draft of a possible implementation...

void TitleMenu::paintEvent(QPaintEvent* e)
{
   //Move down the actions... (?)

   QMenu::paintEvent(e);

   //draw the title
}

I think the idea is correct, but I don't know how to do the first part.



--
 [ signature omitted ]