PDA

View Full Version : Painting primitive elements-PanelMenu does not show



MasterBLB
29th April 2010, 08:37
Hi Brothers

Why the code below does not work?I mean,only the frame is painted.
parallelMenu is a descendant of QWidget.

void parallelMenu::paintEvent(QPaintEvent *e)
{
QPainter p(this);

QStyleOptionMenuItem menuOpt;
menuOpt.initFrom(this);//the rect is set in the constructor by setGeometry

QStyle *s=style();

s->drawPrimitive(QStyle::PE_PanelMenu,&menuOpt,&p);
s->drawPrimitive(QStyle::PE_FrameMenu,&menuOpt,&p);
}

wysota
29th April 2010, 13:20
What is the exact effect you are trying to achieve?

MasterBLB
29th April 2010, 21:01
I'd like to create a popup menu with QAction laying in X parallel columns.
Unfortunetly,there is no such functionality in QMenu (except those when menu exceeds height of the screen,but I can't force to use it)

So I think there is no other way than create my own QParallelMenu from QWidget

wysota
29th April 2010, 21:45
I mean what is the reason for trying to perform those drawing operations.

MasterBLB
30th April 2010, 06:55
I want to draw menu using QStyle by using it's 'bricks':
http://doc.qt.nokia.com/4.6/style-reference.html#menus

But when I use drawPrimitive(QStyle::PE_PanelMenu,&menuOpt,&p); the panel is not drawn :(

wysota
30th April 2010, 07:03
QMenu itself only draws PE_PanelMenu and CE_MenuItems, it doesn't call PE_FrameMenu.


QStyleOptionMenuItem menuOpt;
menuOpt.initFrom(this);
menuOpt.state = QStyle::State_None;
menuOpt.checkType = QStyleOptionMenuItem::NotCheckable;
menuOpt.maxIconWidth = 0;
menuOpt.tabWidth = 0;
style()->drawPrimitive(QStyle::PE_PanelMenu, &menuOpt, &p, this);

MasterBLB
30th April 2010, 08:23
I tried this orginal QMenu code-it does not work.And about painting the frame-look down inside QMenu::paintEvent() :]

wysota
30th April 2010, 08:50
I tried this orginal QMenu code-it does not work.
What do you mean it doesn't work? :) Try surrounding the call with QPainter::save() and QPainter::restore().

MasterBLB
30th April 2010, 09:24
I mean that only the frame is visible,while I expected an plain,empty space.

wysota
4th May 2010, 20:29
Could you provide a mockup picture of what you wanted to obtain and what you did obtain?

MasterBLB
5th May 2010, 06:59
Sure,there is is.
As you can see,element QStyle::CE_MenuEmptyArea,as well as QStyle::PE_PanelMenu is not drawn-only the frame is visible.

Although I managed to develop a solution at least-I draw a large QStyle::CE_MenuItem without neither text nor icon,and then paint test items on it.
But still,I don't know why the orginal code does not work.

wysota
5th May 2010, 09:36
At least for me the image is not helpful in any way, you provided an image of the whole screen and I wanted two small pictures one of which points to what you get and the other to what you would like to get.

MasterBLB
5th May 2010, 11:19
Ok wysota,but in that case you have to wait 'till I come back from work to home.