How to move a QPushButton inside gridLayout? - qt

I have just tried a simple thing, in designer I created one push button, inside grid layout. The problem is geometry option got disabled in Property box, and I am not able to change the cordinates. In this situation how should I move the push button from its original place if required?
Can somebody help me to achieve this??

You can't move or resize a widget inside a layout because its position and its size are managed by the layout. If you want to manage its geometry yourself, do not use a layout.

Qt layouts are designed to help you make scalable user interfaces. For this, moving or resizing the button is usually done by the layout using sizeHint() and sizePolicy().
I would suggest reading up on how to use layouts and the use of spacers, as this will impact the location and size of your button.

Well I found a solution to that
Break the Layout, arrange the widgets and then set the layout

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!

Qt5: how to resize two UI lists against each other

I would like to be able to resize two QListWidget that sit in a QVBoxLayout, by grabbing the edge in the middle of the two and sliding it up or down. One would shrink, the other would get bigger.
Here is a screenshot of a sample app:
I would like to be able to grab the bar between the two lists and resize them.
This is what it looks like in the Qt layout editor:
I'm not sure if the vertical layout is the good choice, here, there may be another vertical layout that provide this functionality maybe?
Is it even possible with Qt?
You need to use QSplitter. It's available in the form designer.
To add to Riateche's correct answer, you can also use qt-designer to add specify the type of layout (QSplitter) by first selecting the widgets and then right-click to layout->horizontal splitter etc.
Here's a simple tutorial I ran by a few years ago: http://www.youtube.com/watch?v=E7Ud6FonsR4

Qt: How to handle forms?

I'm creating an application in Qt (Nokia SDK) which should hold a login screen, main menu screen, etc....
But what is the best way to jump back and forward on these screens?
I have recently looked at Stacked Widget, and it seems like that could solve my case, but it has some kind of margin on itself, that makes it look weird. (Makes the widget not fill the entire screen)
Any suggestions?
Thanks in advance!
if you are using a layout, select it and in properties, set margin values to 0
QStackedWidget doesn't have any margins. You should check if you are using layouts with margins. Usually you will have layout for each page of stacked widget.

Qt: Same Widget Inside Two Different Layouts

What I'm trying to achieve is that a widget could exist in two different layouts, in this case in QHBoxLayout and in QVBoxLayout. I'm implementing a system which dynamically switches between the two layouts when a device's screen orientation changes.
Currently I'm creating, let's say a complex composite widget called MyWidget and adding it into a two different layouts:
MyWidget *wgt = new QWidget();
QVBoxLayout vlayout;
QHBoxLayout hlayout;
vlayout->addWidget(wgt);
hlayout->addWidget(wgt);
Now imagine that both layouts are hosted within a 'root' layout, and that this root layout can resize into a more wide than tall 'landscape' mode, and into a more tall than wide 'portrait' mode.
The MyWidget shows correctly in only the first layout it is added into, and when the layouts are switched, it shows all wrong or not at all.
I don't know if I'm making any sense here, but this is my problem. Maybe when the switch event is called all child widgets and layouts should be resized, so it would always look right. Only problem is that I don't know how.
This isn't a general solution for changing layouts, but an easy solution in your case: Just change the boxlayout's direction.
hlayout->setDirection(QBoxLayout::TopToBottom);
// now your hboxlayout works as vertical layout
hlayout->setDirection(QBoxLayout::LeftToRight);
// and now it is horizontal again
This isn't particularly easy to do, but is possible.
First of all, I'd recommend that you actually create two different widgets, one for the vertical and one for the horizontal, and manage things that way. If the source data is properly separated from the UI class, you should be able to do so without too much trouble, but by incurring some memory overhead.
One way to do as you desire would be to completely remove the widgets from one layout and add them to the other when you need to change the arrangement on the screen, and change the layout that is added to the widget. This should cause the same widgets to be drawn in a different way.
A different, more intricate way of handling this (although potentially more efficient) would be to write your own layout and have it handle rearranging widgets based on the orientation change.

Flex: What OpenSource Container Component should I use?

Please help me what container component I will use. Here is my problem, I have advance data grid with full of data about 300 by 300 row-column(data can be picture). Now I need a container that can zoom in/out, fit to screen capability and can drag around the component inside so that my data grid will be zoomable and dragable around the container(Easy for the user to read content inside my datagrid). Any suggestion for a container that fits on what I need. Thanks
You'll likely have to add some functionality to AdvandedDataGrid to do that sort of stuff. The grid only renders cells that are currently on screen (well, mostly) to achieve a decent performance level. If you enlarged your grid to show all cells and then embedded that into a container that managed scrolling, etc, it would likely be unacceptably slow.
But you could add event handlers directly to the grid to manage your new user gestures.
http://code.google.com/p/flexlib/wiki/ComponentList
Maybe the dragscrollCanvas container, combined with scaleX/scaleY events on the datagrid in response to mousewheeel events for the zoom?
Not sure exactly what you need...
you need to use a custom itemRenderer for your datagrid field. There are some great tutorials out there...
http://www.adobe.com/devnet/flex/quickstart/using_item_renderers/
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html (is a series of
And if you know what you are looking for then I'm sure that you can find the right itemRenderer for your datagrid.
Then using your custom component you can move it around, zoom, etc.
If you are talking about the container that contains the datagrid checkout the flexlib mdi container. This container can have other windows inside of it then you can tile, cascade, fill, etc. This also supports dragging.
example: http://www.returnundefined.com/flexmdi/explorer/
webpage: http://code.google.com/p/flexmdi/

Resources