QT and custom menu item (QLineEdit) - qt

How can I use QLineEdit as a menu item in QMenu? Is there any solutions to do this?
Just to do something like this (look at the edit box under the avatar):

You can use a QWidgetAction to contain your QLineEdit. It inherits QAction.

Take a look at QComboBox. It allows editing of items in a pop-up menu. But if you mean the menu in the main menu bar, I don't think there's a way to do it. And it's not a good UI anyway.

Related

Is it possible to respond to a click on a tiop level menu item?

Is it possible to respond to a click on a top level menu item? For example, referring to the image below, is it possible to run code when the "Help" menu item is clicked?
If so, how do I do that?
Thank you.
You can use QMenu::aboutToShow() signal and do the following:
connect(helpMenu, SIGNAL(aboutToShow()), this, SLOT(onHelpMenuClicked()));
where helpMenu is pointer to your Help menu and onHelpMenuClicked() is slot that will be called as soon as you click on the Help menu.

Does Qt have combo boxes like Word?

In Microsoft Word, if you want to use Bullets you have a combo box (If we can call it a combo box) to select the shape of the bullet (by clicking the little triangle) or you can just apply the default one by clicking the combo box's button.
Actually the combo box in Word has two parts. For an example let's consider a situation where I want to have a combo box in Qt that has these items as menu items:
"Restart", "Shutdown" and "Log off". User needs to choose one of them but he also can apply previously selected item by clicking its button exactly like Windows shutdown menu in start. You can click Shut down or select another option.
How can we achieve this in Qt?
If you are pursuing after a menu that looks like in the second picture, you can use QToolButton to achieve your goal. Use a QToolButton with popupMode set to MenuButtonPopup. It will render a control something similar to following.
Then you can style the look & feel further more using Qt Style Sheets. Read this example on how to style a QToolButton.
Create a QMenu dynamically, so you can attach it to the QToolButton at run-time in such a way that all items will be included in the menu except for the default item. Default action has to be assigned to the QToolButton itself.
You can use void QToolButton::setMenu (QMenu * menu) to assign a QMenu to your QToolButton at run-time.
If you are trying to design a control that is in your 1st screenshot, you will have to create a custom Qt control I guess. There is no default control available, which can yield that look & feel out of the box.

How to hide an ASP.NET menu item?

This question was asked before but what I need is to simply hide a menu Item rather than remove it . I was surprised to see that ASp.NET MenuItem has no Visible property. is there any way really yo hide a menu Item
Thanks
you can hide the menu item using css. just use CssClass property. Using CSS and Styles with the Menu Control
I ran into the same issue and my work around was actually having two separate menus. I assigned my Admin controls that i wanted to hide in its own menu. I positioned them next to eachother as if they are one and i hide the menu when the user doesn't have access in my codebehind.

How to Remove Toolbar from QToolBox control in Qt?

How to Remove Toolbar from QToolBox in Qt?
Normal Toolbox looks like this:
I want to remove this button written with Page 1. Something like this :
I'm not sure if this makes much sense, since those buttons are needed for the functionality of the QToolBox. If you want a stack of widgets for which you can manually control if they are shown or not, then QStackedWidget provides similar functionality without displaying any elements of its own.
edit: No, as the QToolBox it doesn't come with a scrollbar. But since you 'fill' it with widgets of your own, which then are displayed with setCurrentWidget, you can use for example QScrollArea and placing your own widgets inside it.

Using layout of QMenuBar

Is it possible to get layout from QMenuBar object and add items to it. What I am trying to do is a menu bar containing custom widgets (a clock and login/off widget) on the right.
This code crashes.
QPushButton *b1 = new QPushButton("Button",ui->menuBar);
QHBoxLayout *rlayout = new QHBoxLayout(this);
ui->menuBar->layout()->addItem(rlayout);
rlayout->addWidget(b1);
b1->show();
Is there any other way?
Best regards,
Valentin Heinitz
Would it be possible to create your own container widget, put the menu bar in on the left, and the other widgets in on the right? That should get you similar functionality and appearance to the Qt3 version of the menu bar.
You should look into QWidgetAction, that allows you to insert custom widget in a menubar. You would then have to call QMenuBar::addAction(QAction*) to put your QWidgetAction in the menubar.
I know that it is not part of your question, but maybe QDockWidget would do a better job for what you need??
Hope this helps.

Resources