In the C++ GUI Programming with Qt 4 book, it mentions in an example in the first chapter that QWidget serves as the application's main window.
And, on the Qt Reference Documentation: http://doc.qt.io/qt-4.8/qwidget.html there is plenty of information about QWidget.
But, what is the baseline? What does QWidget mainly do? When should I think about it?
One way to think about it is any object that knows how to display itself on the screen is a QWidget (in particular, some subclass of QWidget).
There are some objects like QPicture that represent an image, but a QPicture by itself doesn't know how to put itself on the screen. You usually need to use it in combination with a QLabel for instance (which is a kind of QWidget).
It is an abstract of window objects. Every visible/invisible Qt window-related object inherits from QWidget.
Just consider a vehicle, it is the abstract of cars, trucks and other stuffs.
Widget is X11 parlance for something a bit more generic that what other systems call a control. A widget can be a pushbutton, a listview, a window, etc...
And BTW, it supposedly comes from Window Gadget.
In windowing systems like X11, there is no difference between a toplevel window and a widget. All are called "windows", and all of them have a parent and children (except the root window, which is usually what the desktop wallpaper is drawn on). So it makes sense that a widget can either be a toplevel window (i.e. a child of the root window) or any other window.
Related
I'm trying to write a circuit designer software in QT on Linux. I'm using KDE 5 Plasma desktop and QTCreator as an IDE.
I tried to use QFrame paintEvent to paint on it, and it worked, but when im grabbed the window inside QFrame it moved.
I know about QGraphicsView, but i cant make a custom class and promote it based on that(it's not listed).
How can i create a custom class from a container(QFrame, QGraphicsView or anything) where i can override paint event and also it doesn't move window if i grab it?
Sorry for my poor english.
QGraphicsView inherits from QAbstractScrollArea which inherits from QFrame itself.
So you can keep the QFrame in the form, and keep it promoted to your canvas class, but simply make you canvas class inherit QGraphicsView instead.
Although, my Qt has two differences in behavior from the OP (but I don't use KDE):
Clicking on a QFrame and moving the mouse doesn't move the whole window for me. I guess this behavior for the OP could be changed by reimplementing void mousePressEvent ( QMouseEvent * event ) in the canvas class and giving it an empty code instead. (doc)
I can put QGraphicsView in my ui files, and I can right click on them to promote them to another custom-defined class.
Edit: Found the reason why the window moves on KDE!
I would like to create a Qt window that
can be scrolled/panned by dragging its background (scrollbars should not be shown)
contains multiple sub-widgets at defined locations (which scroll with the background)
the sub-widgets can be resized by pulling their border
What I managed so far is to create a QGraphicsView with setDragMode(QGraphicsView::ScrollHandDrag) http://doc.qt.io/qt-5/qgraphicsview.html#dragMode-prop. I then placed the sub-widgets on a QGraphicsScene, however, this didn't allow the sub-widgets to be resized by pulling their border.
I also tried to inherit my custom sub-widget class from QDialog, which allows setSizeGripEnabled(true). However, this doesn't resize their content, and QDialog is probably not meant to be part of a QGraphicsView.
Any suggestions? It would also be ok if the sub-widgets behave like sub-windows that can also be dragged at their title bar, as long as they cannot be closed and they move when the background is dragged.
You can look aside QMdiArea class (Qt documentation: QMdiArea). By problem description it is what you need.
Of course, you can use Graphics View Framework, but, i think, it will be more difficult. If you choose such approach, very useful will be class QGraphicsWidget (Qt documentation: QGraphicsWidget).
I am trying to create a small application using Qt. What I want to do is to display in a dock widget a 3D Interface using DirectX11, other widgets in the QMainWindow will have properties to modify the behavior of what is been displayed in DX11.
The problem I am facing is that when I add a QDockWidget to QMainWindow, the dockWidgetContents function windowHandle returns NULL.
I am using an example from Get HWND on windows with Qt5 (from WId) to get the HWND. But if the function return NULL it will go up and get the HWND of the QMainWindow.
Is there any way to force a QWidget to have its own window handle?
Thanks for any advice!
Yes. You have several options for that. See the topic Native Widgets vs Alien Widgets in the QWidget class documentation.
Use the QT_USE_NATIVE_WINDOWS=1 in your environment.
Set the Qt::AA_NativeWindows attribute on your application. All widgets will be native widgets.
Set the Qt::WA_NativeWindow attribute on widgets: The widget itself and all of its ancestors will become native (unless Qt::WA_DontCreateNativeAncestors is set).
Call QWidget::winId to enforce a native window (this implies 3).
Set the Qt::WA_PaintOnScreen attribute to enforce a native window (this implies 3).
I am writing an application using Qt and would like to have a "Metro Style" interface. Everything is finished except I don't know how to make the widget appear and disappear. For instance, in WPF you can animate (UIElement.RenderTransform).(TranslateTransform.Y) so that Y becomes zero or negative. How can I move the QWidget in a QGridLayout so that it can hide?
Example:
After doing some research I figured out a way to do this. Instead of letting Qt do the layout I simply handled it myself via move and set width/height functions. Overriding resizeEvent made it so I could update the values in case the window was resized. Additionally I used setMask to ensure that the widget did not leak over to unwanted locations in the UI.
How can I minimize my QMainWindow without also minimizing my QDockWidget that I have undocked and is floating? What I want to do, is take a small window of my GUI to monitor the rest of the MainWindow. The MainWindow does not to be on the screen, all I want to see is the DockWidget while it is floating.
The floating window is almost certainly being minimized when your main window is minimized because the main window owns the child window. Or in other words, the floating window is a child of the main window. And a child window cannot be visible when its owner window is minimized.
The solution obviously is to break the ownership relationship between your floating window and the main window. That will probably also require that you change the type of window that your floating window represents. I'm guessing that a QDockWidget class implements a floating tool palette or other form of pop-up window. In order to have a standalone window, you'll need to create an overlapped window.
Read more about the various types of windows here, at least assuming that you're using Windows.
I imagine that it's a similar state of affairs for the other target operating systems.
On Windows in particular, someone might suggest that you make the floating window a child of the desktop window, but let me take this opportunity to strongly advise you against doing that. For a more nuanced discussion, see Raymond Chen's blog post on the subject.
A floating QDockWidget is automatically minimized when its parent QMainWindow is minimized. There is nothing you can do about that. You may have to change your QDockWidget into a QDialog (or some other QWidget) with parent = 0.