Can't dock a Dock Widget when used inside a Widget - qt

I've insert a Dock Widget inside a widget, and I want to Check the dock Checkbox inside the Designer in order for it to be docked. But this seems impossible to do since it is disabled like shown in the following picture:
I also tried the following line of Code:
ui->dockWidget->setAllowedAreas(Qt::BottomDockWidgetArea);
But it seems that it has no effect...

The 'dock' property enabled in MainWindow Form
if you are using Widget, change it to MainWindow and dock will work properly

Related

Can a QToolbar be added to a QDockWidget?

I have setup my app to have various dock windows within the main window. I am also able to add a toolbar to the main window. However, I would ideally like to add the QToolBar inside one of the QDockWindow instances (or the QWidget that it houses) as the toolbar will be specific to that window.
Is this possible? I'm using a recent version of Qt, 5.10.
I think it is possible.
1.QDockWidget can set a QMainWindow by setWidget() method.
QMainWindow is made for just a mainwindow but it is not prevented from being used as a subwidget.
2.QToolBar can be attached to the main-subwindow by addToolBar() method.
3.The subwidget-mainwindow can naturally have its own QToolbar.
If you don't want to use QMainWindow as the widget of its QDockWidget,you can attach the QToolBar as a child widget of QDockWidget. But The toolbar is not movable as QMainWindow's.
I think you want to add QToolBar and use it as QMainWindow.
So I recommend that you set a QMainWindow as the widget of QDockWidget.And you attach any widget you like to the mainwindow after that.

Qt: mainwindow application

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.

How to detect if focus shift from a widget inside a QWidget to one outside?

I'm programming in Python using Qt with PySide and I have custom QWidget defined in a file called editor.py which is inserted in my ui in windowUi.py using the promotion method in the Qt Designer.
The custom QWidget class defined in editor.py doesn't do much besides using Elixir to edit items in a sqlite3 database and importing a ui file (editor.ui). Inside editor.ui there are a couple of QLineEdits and QDateTime widgets.
This widget is originally hidden in the main window and showed when needed. So far so good, but the problem is that I cannot make it hide when not needed. I decided that the widget is not needed when the user clicks anywhere else in the main window that is not the editor widget imported, that is, focus shift from the QWidget.
I looked upon this question: QWidget focusOutEvent not received and realized that the QWidget is really not getting focus.
If I call setFocusPolicy(StrongFocus) on it then I can make it hide if, and only if, the user clicks on the QWidget background (not on any widget inside it) and then clicks outside.
The question is then, how can I make it such that when the user clicks outside of this widget, shifting focus from any QLineEdit or QDateTime that's inside it to something else, the QWidget then hides itself?
Doesn't QApplication:::focusChanged ( QWidget * old, QWidget * now ) do what you need? You can check if QWidget *now is one of your QLineEdits/QDateTime or not (f.e. by going up by the QObject::parent)
Simply connect to this signal before showing and disconnect after hiding.

Qt gui creation, widget resizing

I am new to Qt development, even though I have years of MFC programming. I am trying to create a dockable widget and put some controls in the dock widget, a tab widget to be more precise. My problem is that the tab widget inside the dock widget doesn't resize along with the parent.
I'd like the tab widget to fill the entire area of the dock widget. Is it possible to manipulate some property in the same gui designer?
I don't know If I understood your question, but try this: click anywhere the DockWidget (and outside the tab widget) and press the button idicated by the red arrow (it will be blue). Is that it?
This:
Becomes this:

QDockWidget move problem when using custom title widget

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.

Resources