How can I add a QLineEdit to Menubar
Asked Answered
P

2

10

I am attempting to reclaim some screen real estate in my application. I've got a search bar that is a basic QLineEdit and takes up space. In my menu bar, I easily have enough room to fit this search box, but I can't figure out how to get the LineEdit into the menubar.

Can someone assist me in getting this added to a menubar?

I am using Qt 4.7.

Here is an image of what I am attempting to accomplish. It's fairly basic image, but I'm looking to use the right half of the menubar as a search box.

enter image description here

Propjet answered 23/8, 2011 at 1:31 Comment(0)
P
18

Use QWidgetAction. QWidgetAction is for inserting custom widgets into action based containers, such as toolbars.

here is an example to add a progressbar to menu bar :

QWidgetAction *widgetAction = new QWidgetAction(this);
widgetAction->setDefaultWidget(new QProgressBar(this));
menubar.addAction(widgetAction);
Precast answered 23/8, 2011 at 6:9 Comment(0)
C
7

You could use

void QMenuBar::setCornerWidget ( QWidget * widget, Qt::Corner corner = Qt::TopRightCorner )

to add your widget in the menu.

Clara answered 30/1, 2013 at 12:8 Comment(1)
Wow.. After more than a half day of different trials and errors this simple method solved my problem :-) (I needed to add a clock to the right corner of my application on the same "line" with the menubar) Thanks!Jackquelinejackrabbit

© 2022 - 2024 — McMap. All rights reserved.