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.
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);
You could use
void QMenuBar::setCornerWidget ( QWidget * widget, Qt::Corner corner = Qt::TopRightCorner )
to add your widget in the menu.
Related
I used QWebEngineView to call html, and now I've shown success. however QWebEngineView is shown in the upper left corner, I want to show QWebEngineView in the white area below. First, I don't know how to do this step.Second, I don't know what kind of Qt should be used in the white area shown.Or you can provide me with a good tutorial to solve my current problem.
This is my interface:
The bar chart is the HTML file I want to display
This is the part of my code:
pEngView = new QWebEngineView(this);
pEngView->setContextMenuPolicy(Qt::NoContextMenu);
pEngView->load(QUrl("file:///html/barx.html"));
pEngView->show();
Use Qt Designer and place a QWidget at the area you wanted. Then promote the QWidget to QWebEngineView and use the ui pointer to get pointer of the webengine widget. If you are new to Qt/QtDesigner follow the tutorials.
http://doc.qt.io/qt-5/designer-layouts.html
http://doc.qt.io/qt-5/designer-using-custom-widgets.html
I would like to build an embedded Qt application. This application shall have a couple of windows which are invoked by button click. I don't know if I understood the concept of using qmainwindow in the right way:
Do I create one QMainWindow class and each other window that should be displayed is a widget placed as central widget or is any new window I call a new QMainWindow?
I do not use qmainwindow's tool, menu or status bar just the dock widgets which surround the central widget, like a header on top and a button bar at the bottom or a widget to the reight like a keyboard. Since the header's label stays the same (only the title and the icon changes) and the bottom bar always holds some button (which should call another central widget or return to the previous one), changing the central widget should be sufficient right?
Have a look at QT Layouts
http://qt-project.org/doc/qt-5.1/qtwidgets/layout.html
Remember you can nest layouts, so you probbaly want a VBoxLayout, and the second entry in that layout will be a HBoxLayout.
On this site
there is a picture with two "tab-systems".
I would like to have the second one, which is described as "A truncated tab bar shown in the Plastique widget style." There you have arrows, which allow you to slide through the tabs.
I have implented a "tab-system" which looks like this:
QTabWidget *tabWidget = new QTabWidget();
tabWidget->addTab(ToolGroupBox(),"Toolbox");
tabWidget->addTab(CameraGroupBox(),"Camera");
...
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(tabWidget);
As I understand it is possible to create the truncated tabs if I use the tabRect-function of the QTabBar-class. I have tried several things but unfortunately its not working.
You want the usesScrollButtons property of the QTabBar. You can access the QTabBar of your QTabWidget via the tabBar method.
You don't need to get involved with tabRect at all. The documentation just before the picture of the two tab systems is not directly related to it. The figure is just showing you two possible tab styles.
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.
I want to create a dock widget with a custom title widget. That custom title widget has my own icons (maximize, minimize, close etc).
Source code is simply like that:
QDockWidget *dock = new QDockWidget("name", parent);
MyDockTitle * titleWidget = new MyDockTitle(dock);
dock->setTitleBarWidget(titleWidget);
When I run the program, dock widget is shown appropriately but unfortunately I can not move the dock widget (it is in floating state). What can be the problem?
P.S. When I dont use custom title widget, I can move dock widget.
Thanks...
The Qt documentation of setTitleBarWidget() says:
Mouse events that are not explicitly
handled by the title bar widget must
be ignored by calling
QMouseEvent::ignore(). These events
then propagate to the QDockWidget
parent, which handles them in the
usual manner, moving when the title
bar is dragged, docking and undocking
when it is double-clicked, etc.
So I guess you need to add some QMouseEvent::ignore() calls to your MyDockTitle class.