PDA

View Full Version : Creating a customizable gui



TMan
23rd April 2007, 11:06
First, the problem:

For this application I want to have a fully customizable GUI. Imagine an empty mainwindow, perhaps with a single fixed element but even that's not sure yet. Now the end user must be able to do something like "insert->widgetTypeA", which would create a widget of Type A in his mainwindow.

Well, that's not too hard, but now I want the end user to be able to resize/move this widget.

At first I was thinking of embedding every created widget in a QDockWidget, but that seems to have serious limitations. First, I can't get the dock widgets to assume a certain size from code, which is important as the user must be able to save/restore the created layout. saveState()/restoreState() doesn't seem the way to go as you don't have a fixed amount of widgets, correct me if I'm wrong.

Second, I don't want to limit the end user to the space of a single main window. Instead there must be some sort of MDI, probably just with a tab widget. This won't work because the dock widget will not dock in the tab widget :(

So, I'm starting to fear that my only solution is to create all-custom widgets, which can be dragged 'n' dropped/resized.

I would welcome any suggestions :)

wysota
23rd April 2007, 11:09
How about using Qt Designer component? Or if you feel this is beyond you, use Designer directly, only modifying the widget box. Then you can create widgets from Designer created forms on the fly.

TMan
23rd April 2007, 11:42
Hmm, that might be a possible solution.

Directly using the designer does not seem to be a suitable solution to me, as that would involve my end users using designer, which is unacceptable.

I don't really see how I could actually embed the designer though? I suppose that will involve switching to some sort of "editing mode" in my application, so the end user is still limited in his/her freedom as it would not be possible to resize/move widgets _really_ on the fly. Apart from that, wouldn't users have to bother with spacers and layouts and stuff in this case?

Was actually hoping there would be a more simple solution ;)

As I'm thinking, wouldn't it be possible to create a class that inherits from QWidget and have that class provide resize/move functionality, after which I can subclass my custom widgets from this class?

Still, it will probably be quite some work to get such a class to behave correctly...

TMan
23rd April 2007, 12:01
Okay, I've been looking around in the dragndrop examples. I've got an idea, but I would like some opinions.

Say I implement the drag 'n' drop kinda like in the puzzle example, but then with my own widgets. So I make some sort of grid (making it easy to predict possible overlap, and generally making it easier to create an "aligned" layout for the end user), in which the user may drop widgets.

Apart from that, I implement some way to resize the custom widgets.

I do this with a class subclassed from QFrame or QWidget, and I subclass my custom widgets from this class so every widget behaves the same.

Sounds like a plan?

wysota
23rd April 2007, 12:03
You can do anything you're able to implement. I just suggested a solution where you don't have to implement anything :) It might prove quicker to train users to use layouts instead of implementing "Designer" from scratch.

TMan
23rd April 2007, 12:18
I didn't completely disregard your reply wysota ;)

Anyway, it seems to me that having users use designer to create their gui's is not a very versatile solution, as it won't really allow runtime editing.

I'll do a quickie on the drag n drop thing to see whether it is a feasible solution :) Might post it here later as it might be helpful to others.

wysota
23rd April 2007, 12:28
Anyway, it seems to me that having users use designer to create their gui's is not a very versatile solution, as it won't really allow runtime editing.
On the contrary. You don't have to compile anything to have a working widget, if that's what you're afraid of. Of course it all might be too complex for your needs.

TMan
23rd April 2007, 12:33
On the contrary. You don't have to compile anything to have a working widget, if that's what you're afraid of. Of course it all might be too complex for your needs.

I do know that. Let me explain.

The application will be some sort of hardware control/data acquisiton control center. So you'll have plots and stuff. Using designer, embedded or not, the user can't really change his gui and still have the plots updating.

Correct me if I'm wrong :)

wysota
23rd April 2007, 12:48
You're wrong :)

TMan
23rd April 2007, 12:51
That's not much of a correction :P

Anyway, there doesn't happen to be an example of designer integration? I couldn't find anything other than the calculatorbuilder example, which isn't of much help.

wysota
23rd April 2007, 12:56
There is an analog clock plugin example in Qt. You can see that it's active (the time passes) in Designer. As for the integration, you need to take a look at the designer component docs and you might also have a look at Edyuk sourcecode. As far as I remember it embedds a Designer component.