Drag and drop of QDockWidget between two or more windows - qt

I would like to know if anybody knows if it is possible to drag a QDockWidget from one window to another.
I am developping an application that has a lot of windows. Each of these windows has a specific usage. I want to use QDockWidget because of the automatic rescaling when docking a widget in the main window. But I would also like to have the possibility to have a new dock area in a new window so that I can put together all the widgets related one to each other.
Does anyone have a suggestion?

As far as I know, you cannot drag a QDockWidget from one application to another if they are developed separately.
On the other hand, I think that you can reparent a QDockWidget to another QMainWindow, only if it's part of the same application.
...aaaaand you can always try to intercept the drap/drop events and pass information between the two windows with a protocol of your own: define a new mime type for the drag and define the syntax of the data associated to the QDockWidget. Then, implement the code to analyze the data and reconstruct the contents of the QDockWidget in the target window... not an easy task!

Related

Qt: Tab Icon when QDockWidget becomes docked

Qt's QMainWindow has a ability to dock windows derived from QDockWidget. It also would put one on top on the other if few of them are stacked, producing a tab bar. Whenever a QDockWidget's state changes a signal topLevelChanged() is emmitted. At this point I would like to get access to underlying QTabWidget to set an icon for a a newly added tab. How can I do it? My patience is over trying to dig the answer out from Qt's documentation and source code. Thank you in advance.
So icon I want to be on Contents/Index tabs.
Once at least one dockwidget has been tabified, the main-window will create a QTabBar to provide the dock-tabs. Each dock-area can have its own tab-bar. These tab-bars will become children of the main-window, so you can use findChildren() or children() to get references to them.
The main difficulty will be in finding which dock-widget belongs to which tab and in which tab-bar. If the dock-widget window-titles are all unique, you can just search using the tabText(). Otherwise, you might be able to use the tabData(), which Qt sets internally to a quintptr from the dock-widget.
Once you have the correct tab, you can of course use setTabIcon() to add your icon. But note that every time a dock-widget is untabified or moved to another tab-bar, the icon will be lost.

Qt desktop application

The Qt desktop application I am required to develop has the following GUI:
The application window is split into 3 parts -
left-side window - has a stack of clickable menu items one below the other. Clicking on each item will show up the corresponding UI elements on the prominent right-side window which is much bigger.
right-side window - contains UI to display some data depending on which menu item is clicked on the left-side window. Each left-side window menu item has a different corresponding right-side window UI.
top (header) window - contains some company "brand" related graphics and also a panel to select a serial port from a list along with graphics to represent connect/disconnect status.
How do I develop this kind of UI? What Qt classes should I be using? I'm a beginner to Qt and would deeply appreciate any help. Thank you.
I'd suggest starting in Qt Designer or Qt Creator to create your UI by dragging and dropping different kinds of objects. Qt Designer is a standalone form designer where Qt Creator is full development environment that also includes the functionality of Qt Designer. Using the form designer is a lot easier, particularly when starting out, than creating widgets programmatically.
There's multiple ways to do the list of items on the left. You can use a QListWidget or a series of individual QPushButton instances, one per option. If the list of items changes, then managing the QListWidget content is going to be easier than instantiating a QPushButton for each item, but you might like the appearance of the QPushButton better. It just depends on what you want.
For the right side, look into QStackedWidget. It's specifically designed to display a stack of content where only one item is available at a time.
For the top panel, again, use the form designer to create the layout. You can store an image in a QLabel. A QComboBox might be what you want for the list, or again, you may want a QListWidget. It just depends on what appearance and user experience you're looking for. For the connect/disconnect status, you can use a QLabel and change out the graphics as the status changes.
You'll need to learn about slots and signals; those are crucial to anything Qt-related.

What to use with Qt for independent windows: a QDialog, a QWindow or a QMainWindow?

I am making my first steps with Qt. As an exercise, I am writing a GUI for a many-core processor, and individual cores are shown in a separate window. From this window, there may be several copies, with their independent life, including menus, status line, etc. That is, they are essentially like a QMainWindow, but having a QMoreMainWindow :). Might be any side effect if I use QMainWindow several times?
Nothing prevents you from using any of them for anything. They do have different roles and properties:
QMainWindow is just that: a main window. It has a toolbar, dockwidgets, a menu bar, a status bar, and a central widget. If you don't need all (most of) those things, you clearly don't want a QMainWindow.
QWindow is a barebones object in which is useful if you don't want/need QWidget's functionality.
QDialog is meant to be used for pop-up windows (i.e. "dialogs") like a messagebox or an open file dialog.
QWidget is the basic window or window element. If in doubt, use this.
Reading your question, it seems you want each of those windows to be a QMainWindow. Note I'd still prefer a custom QWidget with only the parts I needed if I were you. Adding a statusbar and menu isn't that much code.
multiple main windows is no issue at all. I also use them in my application and they work fine. You can either have the main windows separately (no parent) or dependant on some main mainwindow, so that they are closed when the main mainwindow is closed.
When your main windows have independent lives and menus, status lines etc., this speaks even more for multiple main windows that probably should all have no parent assigned.
So, yes, your approach seems perfectly fine to me.

Need help on basic Qt structure

Hi I am a Qt beginner. I want to make something like a column of icons on the left, after click the icons different forms and results appear on the right, how can I do this? Should I choose QMainWindow or QWidget for this project?
should I choose mainwindow or widget for this
project?
If what you described are the only things present in the window, you should use a QMainWindow. If you think you will want to re-use this arrangement in the future, I'd use a QWidget. It will probably be easier to implement each set of forms as a separate QWidget (in Designer; if you're building the GUI programmatically, just add the forms to a QLayout in a QFrame).
a column of icons on the left, after click the icons different
forms and results appear on the right
For the column of icons, you should look at QListWidget. It provides a vertical list of QListWidgetItems, and the items can contain icons, and nothing else. Your main window can then connect to the list widget's currentItemChanged signal (or itemChanged or something else; there are several choices), and modify the forms in the right-hand side of the window appropriately.

Attach Qt windows?

Is there any way to attach two Qt windows together? For example, if window A is the main window and window B is another widget I want to be able to show window B to the side of A and have both windows move together if the windows are dragged.
Not that I am aware of, but you can try following the trail of QMoveEvent. When a given widget is moved void QWidget::moveEvent ( QMoveEvent * event ) is called, and the QMoveEvent contains both old and new pos. Using this information, you can inject a move event in the other widget as well, and make it follow.
Of course, I am speaking of two independent widgets, each one in its own window. If they are contained, you don't need anything but a Layout management (see QLayout and related classes).
I don't work with Qt since a long time, so there could be a better method, but if I had to do it right now, this is the strategy I would use.
Also, I have the feeling that the QMoveEvent will be invoked only at start and end, unless you enable mouse tracking. If the former is the case, you will obtain that the other widget will "teleport" at the end of the move, instead of following smoothly.
You might be after something like this:
http://doc.qt.io/archives/4.6/qt4-mainwindow.html
Window A would be a QMainWindow and window B would be a QDockWidget.

Resources