QT how to get rid of spaces between widgets and their parents - qt

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.

Related

Custom shaped menu with shadow in Qt

I'd like to create a context menu looking similar to this one:
I read suggestions on the web that QWidget::setMask() should be used to create a shape. But how can it fit the variable number of items then? Moreover, the same menu item may take more or less screen space on different machines.
Another question is how to create a shadow around this custom shape? As far as I understand, the mask allows to crop the widget, but not to make it semi-transparent.
I don’t found an easy way to do that! But here goes a way!
Instead of using the Qt mask API, I've used a frame-less widget with transparency enabled!
To draw the shadow, I've used radial gradient!
You can change the size of the menu before opening it, however you can’t resize it after opened (for example resize with mouse).
It’s quite easy add or remove widgets, just respect the layout margin to not draw outside the bounds destined to widgets. To simplify your life I created an inherited class of QPushButton with colors you can easily customize with style sheet.
See the result:
You can browse the source
Hope that helps!

NSSplitView with toolbars

I'm trying to make an application that looks like the Messages app from Apple.
The NSSplitView has toolbars on both subviews of the NSSplitView. They blend in with the top toolbar. It's similar to the NSToolBar but that doesn't work in NSSplitView's. Is there any way to make this work?
I tried the CNSplitView but it doesn't provide the proper effect. Is there another way of doing this that I'm missing?
The interface i'm going for is here:
Instead of using NSToolbar, you can add your own views to the top of subviews in the NSSplitView to achieve this after hiding the existing titlebar.
NSWindow's titleVisibility can be used to hide the built-in titlebar, and by setting the window's styleMask to include NSFullSizeContentViewWindowMask you can cause the split view to take up the full height of the window.
To get the blur effect like toolbars/Messages you can use NSVisualEffectView in the top views. Setting the material NSVisualEffectMaterialTitlebar will give the same look as standard titlebars.
And finally, you can put NSStackViews inside the visual effect views, and then place the titlebar controls in there.
(And depending on the content that is below your fake toolbars, you might want to look into NSScrollView's contentInsets property to allow the scroll view to show all of the content, but still be able to scroll under your toolbar).

How to make bootstraps's "split button" in Qt widgets

This is probably simple, though I can't find the correct CSS trick to handle this one.
I want to have this kind of button-group (separated with lines, containing a context menu ) in Qt. They must have native look and feel (not like below examples) so the only needed change seems to be removing rounded corners of a QPushButton from its right side (for left-most button), left side (for right most button) and both (for buttons in the middle).
Qt does not support this. You can use CSS to style the buttons like in the example, but you can not use natively styled buttons like this.
If you really need this, the only option I see is to write custom controls for this, with customized drawing code for each OS GUI style you want to support.
You could also try to use standard buttons that overlap and use custom code to paint some kind of line over the overlapping region, but I don't think that would be a good solution.

QWidget with movable/draggable children

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

QToolBar: styling 'show more' button

Does anyone have idea on how to style this rectangular button -which is a default child of a QToolbar?
First two images show the button when the graphical interface is on normal screen mode. It appears; since toolbar icons don't have enough space. Third picture shows fullscreen mode, in which my icons have space.
I want to style its shape, so that it has a radial border, without a corner. This will cancel its ugly look, in second image.
I want to let users use the interface in normal view, so locking application to fullscreen is not an option. I do want to use the button, so removing is not acceptable. Styling its position to 5 pixels left or replacing it with another stylable button could be possible solutions, but I couldn't manage to do them.
I played a lot with toolbutton and pushbutton stylesheets, but had no luck on styling this small button. I am pretty obsessed about my graphical design, but don't want to waste too much time (if solution is not trivial, I will change my toolbar to a rectangular one).
Thanks in advance.
I found the solution by listing the children object names of my toolbar.
QStringList list;
for(int i=0; i<toolBar->children()->size(); i++)
list.append(toolBar->children()[i]->objectName();
Inside the list, there is only one object that has a default name (not " "). It is qt_toolbar_ext_button
Then I was able to style it as:
"#qt_toolbar_ext_button { //... }"
I know this has been answered, but for anyone who needs to know the answer its a "QToolButton" and if you need to style a specific button with an object name you do "QToolButton#objectName" in an external resources file stylesheet or in the Widget UI stylesheet dialog for different objects.
QToolButton#objectName {
}
Check out the documentation - http://doc.qt.digia.com/4.2/stylesheet.html
This gives you the syntax for stylesheets in Qt, or "QSS" files.
Just do it: Qt documentation about stylesheets

Resources