I'm looking for an existing solution in Qt5 which would allow me to construct a QWidget with horizontal layout with some child widget which would be movable within parent widget area.
As an example of such behaviour you may try to play with tabs in firefox - user can drag a tab and move it right and left and other tabs are drawing aside to make a place for dragged one.
Also I'd like to be able to drag and drop child widgets from one parent widget to another, like in case of firefox: one tab can be dragged to another window. However in my case drag and dropping would occur in one application.
Is there such a solution or I've to do it myself?
I am using Qt4 but I am sure that the following should work for Qt5 too:
For moving tabs within tabwidget there is a API "setMovable (bool movable)" available in QTabWidget class.
To your other requirement you may need to do a little bit of coding. You should look into documentation of QDrag class and
examples of drag-drop in qt installation (examples/draganddrop) folder.
Santosh
Related
This is a screenshot of a QFormLayout holding a series of widgets. Note that the top and bottom input widgets are not horizontally aligned to the middle two rows. Note also that the labels on the left are not vertically aligned to the middle two rows.
The difference is that the top and bottom widgets are plain QLineEdit and QTextEdit widgets, the second row is a QWidget with a QHBoxLayout holding a QSpinBox and QDateTimeEdit, and the third is a QStackedLayout containing QWidgets each with a QHBoxLayout and API-supplied widgets inside those.
It looks like these middle two have extra margins. I can (partially) improve the situation by calling QLayout::setContentsMargins on the plain QWidgets' layouts. In fact, in the image above I already have, without that it's worse.
I haven't interfered with styles in the application, it's all system-default. This seems to affect Qt5 on Ubuntu 15.04, I don't think I saw this back when it was a Qt4 application.
I tried setStyleSheet ("QWidget {margin:0;}") in the top-level widget, that introduced all sorts of problems. I also tried the variation setStyleSheet (".QWidget {margin:0;}") but that had no effect. QLayout::setSpacing also had no effect, and setting padding:0 in the stylesheet doesn't fix it either.
Nothing I've tried seems to bring the spacing around these custom-layout QWidgets in line with the API-supplied widgets.
What have I missed? Thanks.
What you observe is both the struggle of multi-platform ui and the simple fact that some widgets are horrible. Given a limited amount of time and a big task, dev teams will not treat fairly the set of features. Powerful widgets and layouts like standard widgets, QGridLayout, will be maintained day and night to be defect free while legacy widgets like QStackedWidget will be pushed at the bottom of the maintenance queue.
I tried to reproduce your issue using designer alone and here is what I got (Qt 4.8) :
What you can see:
The second line with a widget container has great marging
The third line doesn't even show the combo box (I swear it's there!!).
My two cents :
There is a difference in behavior in the second row. Because I used Qt4 and you Qt5, and we both set the QHBoxLayout margin to zero then it means there is a potential regression at play, either in Qt5 or the linux implementation. So this confirms what you suspected.
QStackedWidget is horrible. It is the usual widget provided to give quick and basic functionality rather implementing the real deal. Here it would be a widget with a QStackedLayout. Like I said I suspect those kind of widgets to receive less love when big development efforts are required.
In these situations, use QGridLayout instead of a QStackedLayout of widgets with layout of widget. It will solve the issue of labels not being aligned. Difficult to set up at first but the result is usually neat.
By the way, I switched to a widget with a stackedlayout and here is the result :
Is it possible to make a borderless window on Qt? I know its possible in Visual Studio you just change the value in the properties window. Qt doesnt have a formborderstyle property.
Also is it possible not to display icon on taskbar
I think it is not possible to suppress the taksbar entry. Each top level window without a parent will get one.
It surely is possible to create a frameless window. I once used a plain QWidget for a similar purpose and add something like the following:
setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);
Setting the window flags using setWindowFlags() on your top level widget with
Qt::FramelessWindowHint - Draw without window frame
See the full doco at http://qt-project.org/doc/qt-4.8/qt.html#WindowType-enum and http://qt-project.org/doc/qt-4.8/qwidget.html#windowFlags-prop
As for hiding the taskbar look at this stack overflow example Qt Hide Taskbar Item (just sets the windowFlags to include Qt::Dialog you could do what your looking for with
MyWindowWidget(QWidget *parent)
: QWidget(parent, Qt::Dialog|Qt::FramelessWindowHint)
I am developing a tool which will have some variable sized windows. I am able to achieve this using the QSplitter horizontal & vertical. Please see attached image.
Now, how to make these individual windows detachable/maximize/close? How can I add cross markers at the top-right-corner of each window so that they can be closed maximized or detached from there? Just like this link :--
http://vector.com/portal/medien/ecu_testing/tae/test_automation_editor.png
You're looking for the QDockWidget class:
The QDockWidget class provides a widget that can be docked inside a
QMainWindow or floated as a top-level window on the desktop.
QDockWidget provides the concept of dock widgets, also know as tool
palettes or utility windows. Dock windows are secondary windows placed
in the dock widget area around the central widget in a QMainWindow.
Check out this example
In 2021, there is KDQDockWidget, an apparently much better Qt docking framework with both commercial and open source licenses.
The site lists the following advantages:
It provides advanced docking that QDockWidgets doesn’t support.
The layouting engine honors min/max size constraints and some size policies.
Supports PySide2 bindings.
Clean codebase.
Supports lazy separator resize.
You can reorder tabs with the mouse.
Supports partial layout save/restore, affecting only a chosen sub-set.
Allows double clicking on title bar to maximize.
Allows double clicking on separator to distribute equally.
Shows close button on tabs.
Allows you to make a dock widget non-closable and/or non-dockable.
Provides an optional maximize button on the title bar.
FloatingWindows can be utility windows or full native.
I love designing my userinterfaces in qtdesigner because its just so damn simple. However, there is always space in between widgets and their parents which i want to eliminate.
Example of problem
I create a simple dialog and add a webview to it. Then layout horizontally.To make the parent more obvious I modify its css to make its background color green
Voila, I want to get rid of the green sections because in my view they make the program look ugly.
Link to my ui file.
Download ui file from my dropbox
or get it from pastebin
In Qt Designer, select your top level widget (in this case Dialog), then look at the Property Editor on the right-hand sidebar. Scroll all the way down and you'll see a section referring to the layout assigned to that widget. You want to change the layoutLeftMargin, layoutRightMargin, etc. properties.
I would like to create a simple effect with my qt gui, but i have no idea how to achieve this.
I have several widgets, that i implemented as subclasses of qwidget. These are part of another widget and live in a layout. When the mouse hovers over these widgets, i want them to appear bigger to highlight the selected one.
This is what i already tried:
Override the paint event, and simply paint it bigger. But then, the other widgets that also live in the same layout overpaint the oversized areas.
I also tried to call the paint function "by hand" from the parent window, to get control over the painting order. But that didnt help either.
I think there has to be a possibility achieving this effect this qt, but i simply dont know how.
Any ideas?
You could either:
create your GUI inside a QGraphicsView, with QGraphicsWidgets and use setScale when the mouse enters or leave the widget, or
use QML.