How to change a widget ancestor in Qt Creator 2.2.0 Designer
-
Hi everyone,
I'm designing a QDialog in the Qt Creator 2.2.0 integrated GUI Designer, and I added a few widgets, but if I drag a widget on top of another, the widget being dragged becomes the child of the bottom widget.
After that, the Object inspector tree shows that the bottom widget becomes the ancestor of the top widget, now, how do I set the top widget ancestor so that the bottom widget isn't it's ancestor anymore?
I clicked everywhere, googled, searched the Qt Assistant to no avail, does anyone now if this is even possible in the designer? thanks!
-
This happens only with bottom widgets that are containers (e.g. QWidget, QGroupBox, QFrame and the like).
You can break the parent-child relationship by dragging the child, moving it out of the parent and dropping it on another place, e.g. on the QDialog itself or another container.
To make room for the new widget, it can help to break an existing layout (if there is any).
If you can make a screenshot of your dialog in designer (not of the preview), we can have a closer look.
-
Maybe it's a design issue (on my part), here's how my app works:
On Startup, it opens a QDialog created with Designer, the dialog is gonna be a frameless window with a transparent background, that way, the background is a PNG image, so you have a simulated uneven shaped window:
the main() code goes like this:@
SplashDialog s;
s.setWindowFlags(Qt::FramelessWindowHint);
s.setAttribute(Qt::WA_TranslucentBackground);
s.show();
@Now, the SplashDialog image background is placed with a stylesheet property in a QWidget, because the window background is transparent, so if I put the image in the window background is invisible.
The thing is that when I start to place my widgets on top of the qwidget that has the background image, the widgets get attached to the widget.
What way would you recommend I place my background image on the dialog? is placing it in a widget ok? and just settle with the fact that the widgets on top of it will be attached to it? or is there a better way?EDIT:
Sorry, didn't mention why it's important not to have the qwidget as ancestor, it's because all of the other widgets on top of it inherit it's properties, so all of the widgets automatically get the background image as well, and they loose all of the system style. -
to answer my own post, I changed the CSS like this on QWidget:
@
QWidget #myWidget
{
background-image: url(:/image.png);
}
@
That way, the property only applies to the widget, so, even though the widgets on top are still children of myWidget, at least they don't inherit the style anymore.It would be nice to have a way to change a widgets ancestor from the object Inspector though
-
The parent-child relation is used to clean up the widgets when the dialog is deleted. For that to work all the widgets of the dialog must form some kind of tree. For widgets the relationship also expresses "contained in" (with parent-less widgets being windows).
I really think that makes sense and see no need to allow for arbitrary parents in widgets.
-
@Tobias - Well, I'm not saying that there shouldn't be a tree, but it would be nice to control the widget tree graphically the same way you control it programmatically, in code you can choose who's ancestor of who, and in designer it's a lot more inflexible because you can't really do that.
Also, I've never really used designer before, and I think the GUI designer is really dated, It's so odd to see the background with dots for the window background, and also not having any alignment guides, it feels so VB6
I guess what I'm about to write maybe belongs somewhere else, but it would be nice to see a more updated editor, sort of like Netbeans swing GUI Builder (formerly matisse) it has all this automatic alignment guides, autoresize based on certain widgets and all other goodies, or also like another product named REALStudio from REALSoftware, those are more modern designers, it would be cool to see a more updated designer instead of a more 80s-90s GUI designer look.
Besides that, it's really easy to use, it has all a GUI Builder needs, it's really nice, the last stuff I wrote are just suggestions, keep up the good work!
Thanks!
-
You do use layouts in desginer, don't you? They are far more flexible and powerful than anchors (think of a grid layout, or even a form layout that automatically adapts to the style of the OS). Once you have one or more layouts in your widgets, they resize automatically.
You can find a quick start tutorial "here":http://doc.qt.nokia.com/4.7/designer-quick-start.html and some more infos about layouts in desinger "here":http://doc.qt.nokia.com/4.7/designer-layouts.html
I once had to use anchors for layouts etc. in Delphi and found it extremely awkward and unintuitive to use.
The parent-child relationship for widgets directly influences the layout and visibility of the widgets, so that is done using drag'n'drop within the form, not in the object tree.
-
Raul: I guess you are not using layouts then: They make the whole guidelines business obsolete. You even get sensible object trees out of designer:-)
-
I do use layouts, but layouts aren't perfect, when you have widgets with a more complex layout than a grid, the layouts don't align as expected, for example, here I'm building a transparent window and a background image to simulate an uneven window, so the layout I'm using for the widgets isn't a grid.
But I guess if you guys that are more used to complex layouts, I'll practice more on using them, maybe there are better ways of using them than the way I use them right now, which I'm not that experienced on them.
I come from the java world, and the java layouts left a lot to be desired, that's why I prefered aligning the stuff myself, but I'll practice more on Qt layouts, maybe, as you say, are a lot better.
-
Ok, agreed. The standard layouts fit best for rectangular shapes. But all this should be doable for non-regular shapes too. A wild mix of horizontal and vertical box layout does some good tricks, especially when some spacers enter the playground. Maybe you can post an image of a scribble for the dialog somewhere.
-
As you will see on the image, there's gonna be a splashscreen, and the window is gonna have a transparent background and frameless, so it's gonna be sort of like an adobe CS app, that it's splashcreen art kind of "goes off" the square window, so it breaks the square line.
The alignment part comes from the program options, you can choose what option to start working with, but the links that are gonna open the window you choose, have to be aligned around the logo, and then each top link has to be left-aligned with the corresponding bottom one, in the image you can see the alignment guides in light blue.
I'm thinking more and more apps are gonna start getting more odd alignments because of how people are demanding more visual coolness because of all the RIA hype. Maybe not everyone will need it, and I don't use QtDeclarative for this because of lack of knowledge from my part on how to do the same thing as I do with widgets.
Here's the image:
-
You could write a custom layout for something like that or give Qt Quick a try.
-
[quote author="Raul" date="1302092643"]I've been meaning to learn Qt Quick but where do I start? [/quote]
Try here: http://developer.qt.nokia.com/wiki/Qt_Quick :)