How to add the common navigation bar to a Meego app? - c++

When using the Meego Touch Framework, the standard MApplicationWindow has the common navigation bar (with the switcher, menu and close buttons) already attached.
For example, the following code:
#include <MApplication>
#include <MApplicationWindow>
int main(int argc, char *argv[]){
MApplication app(argc, argv);
MApplicationWindow w;
w.show();
return app.exec();
}
Creates a blank window with a menu bar that looks similar to this (eg. the switcher button, menu and close button along the top).
However, since the the docs discourage the use of the Touch Framework I want to avoid using it, so how would I create a similar looking window using only the standard API?

How I would implement this, would probably be a fixed height, variable width QHBoxLayout with a stretch factor for those indices that need it. Then I would just use QPushButton and QCombobBox for the widgets and finish them off with a custom stylesheet and icons. I would then wrap these inside a neat little custom widget that I could reuse in my main view class.
The main view should be a window class that would hold the navigation bar widget on top of a QVBoxLayout, and the actual content below it. The bottom index would have a stretch factor to it, so that the upper index would always be at the top.
I don't quite remember how the Meego handset UX should act like, but that's how I would create a similar looking navigation bar.

I would just go with the QMainWindow class, as this class already has menus, toolbars, statusbar aso.
You should however take care of the orientation switching yourself (I see that the toolbar in portrait mode is at the bottom, while in landscape mode it is on the top).
This could be accomplished by setting the right Qt::ToolbarArea value.
The style of the buttons and the window itself, can be set using a Qt stylesheet.

Related

Is there a way to attach or anchor two QWidgets together?

I'm getting started with Qt and decided to build a full-screen text editor. I want to have a button (button with arrow in screenshot) attached to a QDockWidget which opens and closes it so the button is always visible to the right side of the screen and stay anchored to it when dock is visible or resized.
My current app is a simple fullscreen textEdit set to centeralwidget in Mainwindow.
I haven't found a way to do this yet with layouts or existing addAnchor() functions so any help or direction is appreciated.
You can achieve what you want by using a container for your text edit and the button. A QWidget instance can be used as an "invisible"*** container for other widgets.
So in Qt Designer you add a widget as a central widget of the main-window, inside this widget you add the text edit and the button, then you set a vertical layout for this container widget.
Don't forget to restrict the docking widget to only dock to the right side, you can do that with: dock->setAllowedAreas(Qt::DockWidgetArea::RightDockWidgetArea); //assuming dock is the pointer to your QDockWidget.
In case you want the dockWidget to be able to dock to any side and the button to follow, you can do that too, but it get a little bit more complicated. Basically you need to connect a slot to dockLocationChanged of your dockWidget and based on where it's docked you need to set-up a new layout for the container widget to be vertical or horizontal and the order of the textEdit and the button based on the side the dock happened.
LE:*** you will most likely need to set the margins you want, since both the widget and it's layout can have them and the actual content might have higher spacing than you want.

Modifying the QDockWidget default snap locations?

I am trying to model a UI from a wxWidgets application to QT. However, in the original application they have Dock Widgets that can snap in place and move around except for occupying the main window.
Every box appears to be a dock widget except for the main window. And if I want to move the Datasets window (top left) to the right of the Output Adjustment window I can:
So now my goal was to try and get the UI in QT to at least accomplish the dock widgets on the left side of the main widget. Which in my case, I was able to at least get the width and the height with some trouble to show up the same. However, I cannot create a QDockWidget like the Output Adjustment and have it snap next to the others. And the other problem comes when I try to move a dock widget it will not snap to the right or the left of the other widgets.
This is where I have my problems. I cannot snap it to either side of the dock widgets. Is this something that will need to be hard coded? I know I have seen other examples online that look awfully similar to this layout. However they are all hard coded. And it would be a lot more simple if I could just use the creator to add the sliders and toolbars as time goes on. And if it is not something I have to hard code, how do I modify the locations on where my widgets can snap? I tried to make a grid layout, however the widgets do not go into the grid.
By enabling dock nesting in your main window you can achieve a more flexible placement of the dock widgets, including positioning the dock widgets side-by-side. In Qt Designer, select the main window and in the Property Editor panel mark the dockNestingEnabled check box (present in the QMainWindow section). Alternatively, you can achieve the same result by calling the method QMainWindow::setDockNestingEnabled in your code.
If you want your application to start with dock widgets arranged side-by-side as in your reference application, you have to resort on the method QMainWindow::splitDockWidget. For example, you can create an initial arrangement in Qt Designer such as the one depicted below.
Next, you can rearrange the dock widgets in the main window constructor code,
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
// Changes the dock widgets arrangement.
splitDockWidget(ui->dock1, ui->dock3, Qt::Orientation::Horizontal);
splitDockWidget(ui->dock1, ui->dock2, Qt::Orientation::Vertical);
}
which would produce the result below.

Close button on QTabWidget not the Tabs in the QTabWidget

I am using Qt-5.8 over Ubuntu.
This is how my QTabWidget appears :
And the black dot is where I want the Minimize Button to happen.
One way I came across is that I can use QToolButton *qToolButton to create a new button and tabWidget->setCornerWidget(qToolButton) and then add the implementation over its click event.
But should there not be any other way to just show the minimize button as like in MainWindow or SubWindows has. Which just minimizes it.
Minimize button on top panel of your QMainWindow's instance is part of Windows Manager subsystem of your OS. So you can't use similar approach inside your window as toolbox with buttons, etc.
As you wrote, try to use tabWidget->setCornerWidget(qToolButton) to place your custom minimize button inside your window.

Qt/C++ Technique To Show Inline Dialog

I have QtCreator 5.5 for the Mac, using C++, and I'm new at this. I have a MainForm window. I want to show a dialog inside that but draw it separately in its own UI designer. Then, at runtime, my code will pull that other UI and show it inside that window.
Imagine for instance a main application window. You click a button and you need to see a confirmation dialog. Normally you could do that with a separate window. Instead, I want it to be inline at runtime, to show it like a widget on the main window.
Sure, I could draw my dialog on top my existing window in a widget, but that defeats the point where I want to be able to adjust it in its own designer window, and just load it as necessary in the main window when I need it.
What's the technique in QtCreator and C++ to do this?
Open QtCreator. This task can only be done through there.
Assuming you have a regular Qt Widget Application, you need to just add a QWidget control on the MainWindow's centralWidget in the UI Designer.
Next, click Edit in the UI Designer and then rightclick Forms. Choose Add New...
In the dialog that opens up, choose Qt > Qt Designer Form Class, and click Choose...
Select Widget and then go with the defaults on the rest. This creates a widget called Form, and the form.h and form.cpp will also be added to your project.
Now find the form.ui and open it in Qt Designer. Add a Stacked Widget Control on the QWidget form. Size it to the same size as the parent widget. Next, stick a Label Control on the Stacked Widget Control's first page. This label will be temporary just to prove that this works. You'll set it to the text of "Testing". Now close the designer.
Flipping back to your UI File of your Main Window, find that QWidget you added and rightclick it. Choose Promote... and a dialog box appears. In that dialog, set Promoted Class Name to Form and then set Header File to form.h. Leave everything else on defaults and click Add and then Promote.
You may be expecting to see an immediate change in your Main Window in that QWidget that you added previously. However, that's not how this works unfortunately. You only see the change at runtime. So, now you should Run your application in Qt Creator. You'll see when it runs that your widget now contains the contents of that form.ui component you created.
Now, here's where it gets interesting. You can now draw all your inline modal dialogs on that form.ui, just putting them on different pages of your Stacked Widget control. You can also set the properties of your widget so that the background of the QWidget container is opaque and dark (creating a background dimmer) and then, at runtime, resize the QWidget to the size of your Main Window. When you need to switch to a different dialog, you can use setCurrentWidget() or setCurrentIndex() on that StackedWidget item like so:
QStackedWidget *w = ui->widget->findChild<QStackedWidget *>("stackedWidget");
w->setCurrentIndex(1);
In that example, I had a QWidget control on my MainWindow named simply widget. I then found the control on it called stackedWidget. Once I had it, I used the setCurrentIndex(x) method on it to change the page of that widget to show the one I needed. Remember that this is a zero-based index. So, (1) would be page 2.
QMainWindow::setCentralWidget
Inside your QMainWindow constructor add:
MyDialogClass myDialog = new MyDialogClass();
setCentralWidget(myDialog);

How can I prevent Gnome from showing two windows when doing alt-tab? (c++ qt app)

(see edits)
I'm developing a QT/c++ application under gnome.
The application a main window and QListBox child window.
Both of these windows show up as separate main windows when I alt-tab away from the application.
How can I make it so that only one window is shown when I (or later the user) uses alt-tab?
I am guessing this behavior comes because one main window doesn't clip the subwindow - the subwindow extends the boundary of the main window. Gnome has bad alt-tab behavior for a number of other applications too, showing modal dialog boxes separately from main windows. But in the case of my app, this is really annoying.
I am thinking I could make a giant transparent window that includes both existing windows. But it would be nicer to find a "clean" solution.
(the most logical guess is indeed that it has something to do with window flags. I've tried every reasonable combination of flags I could think of. The window types are described here)
Edit:
The app has a QWidget as its main window (Not QMainWindow), QListView is contained in the QWidget object and created by passing a point to the main window.
is styled with Qt::Tool | Qt::FramelessWindowHint.
Edit2: The Qt::X11BypassWindowManagerHint style does work to remove the window from the alt-tab list. The problem is that it also makes the window "unmanaged" so it cover the other windows. I could manaully hide whenever I lose focus - prize now for a better solution.
When creating a window for your QListBox window set a Qt::Tool window flag in its constructor or later with setWindowFlags function call. Here is some code snippet(I omitted the headers):
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QMainWindow mw;
mw.show();
QWidget toolWindow(&mw, Qt::Window|Qt::Tool);
QHBoxLayout layout(&toolWindow);
toolWindow.setLayout(&layout);
QListView lv(&toolWindow);
layout.addWidget(&lv);
toolWindow.show();
return app.exec();
}
I've tested this on my Debian sid box (Gnome 2.30, metacity 2.30.1) with freshly created user: .
If this is not what you wanted, then please name the software which works correctly or you may check it yourself. To do this run xprop in terminal window and click on the window you are interested in. The output will contain window flags. The one you are interested in is _NET_WM_WINDOW_TYPE(ATOM). For the tool window(i.e. not listed in alt-tab) this flag is:
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_UTILITY, _NET_WM_WINDOW_TYPE_NORMAL
If the window with these flags is not a toolbox window then something is wrong with your window manager or you have personally set such behavior.
You can try it by hand with the wmctrl tool. With "-r -b SOMETHING" you can modify NET_WM arguments to it. Try these in [1].
If this works, you can add them in with Xlib-Calls (If you get to know X11 Window Number from Qt. I am sure that's possible).
[1] http://standards.freedesktop.org/wm-spec/1.3/ar01s05.html