PDA

View Full Version : How to create .ui file from hand written header and source files only.



Badeand
22nd March 2011, 13:59
Hi everyone,
As I write this message I am in the middle of my big student project involving a lot of coding in Qt, and I have stumbled over a matter that I needed some help with.
As of today, all my code is in header and source files only, and I never even opened Qt Designer. The issue is, I need to be able to move my buttons around, and rescale some of it, and doing this by hand can be quite hard and time consuming, seeing that I don't have much time left before my deadline.

As of today I have 16 source files, and 16 headers, and when I build it it pops up almost as I want it. All I need to do, is insert some custom buttons instead of the boring gray ones, and rearrange them a bit so the final result looks better for the user.

So, I guess my final question is: "how do I create a .ui file where I can arrange everything as I want, but create it from the sources I already have (not a new project)"

I really hope there is a quick solution somewhere that I overlooked. (I'm a Newbie when it comes to Qt)

yours truly,
Badeand

Archa4
22nd March 2011, 14:13
RMB on the project name on the left, then Add New -> Qt -> Qt Designer Form...
But I cannot be sure that this is what u want...

Badeand
22nd March 2011, 14:23
Hi, thanks for answering =)
No, this just creates a new blank UI, what I want is to create THE UI, from my source files, so that what I see when I build my project, is what I will see on my UI form (that doesn't exist yet).
So I want to somehow port my program to a more editable state.

Hope you understand,
Badeand

Archa4
22nd March 2011, 14:26
Hm... But is this even possible? I think not...

Badeand
22nd March 2011, 14:30
I really hope so, cause if it ain't I have A LOT of work to do... I need to somehow implement custom buttons (made by me in Photoshop), and move them where I want them to be, and a lot of other Design stuff, to make my program more attractive.

SixDegrees
22nd March 2011, 14:33
Designer work only flows one way - from Designer to UI files to C++ files, with a few intermediate steps along the way. You can't get Designer to ingest existing C++ files and understand the layouts. At this point, you'll have to make your changes by hand.

Note for the future: always keep your UI code separate from your program's guts. You never know when a new UI might be required, and if someone comes along and demands, say, a Java front end then all you have to do is rewrite that and not the entire program. In your particular case, you could have turned to the Designer and grafted its output onto your backend without much trouble. Too late now, from the sounds of it, but something to keep in mind for next time.

Badeand
22nd March 2011, 14:41
Actually my Ui code is in a separate source, called mainwindow.cpp and mainwindow.h, does this help? The thing is its a program that moves from person to person over the years, so I am working on someone else's work, and every year a new person takes over and "makes it better". Its a student engineering project to show us what will happend to us when we get out working =)

wysota
22nd March 2011, 14:41
I have a tool that is more or less able to do it but at a current state it would require your dialogs to use layouts which I doubt they do, if I correctly interpret what you say. Besides the tool is not free. I could probably do the translation for you but not for free.

Badeand
22nd March 2011, 14:47
I think I use layouts =)
Example1:

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), mdir("messages.txt")
{

QTabWidget* tabw = new QTabWidget;
QWidget* cpwidget = new QWidget;
QVBoxLayout* playout = new QVBoxLayout;
QGridLayout* pgrid = new QGridLayout;

socket = new LHCPSocket;
QWidget* cwidget = new QWidget;
QVBoxLayout* toplayout = new QVBoxLayout;
QGridLayout* grid = new QGridLayout;

Example2:

toplayout->addWidget(new ConnectBar(socket,mdir.getMsgInfo("SHUTDOWN_SERVER")));
toplayout->addWidget(map);
toplayout->addWidget(supportb);

Due to copyright material I can't post more "explaining" code... but maby this helped you a bit?

SixDegrees
22nd March 2011, 14:50
Actually my Ui code is in a separate source, called mainwindow.cpp and mainwindow.h, does this help? The thing is its a program that moves from person to person over the years, so I am working on someone else's work, and every year a new person takes over and "makes it better". Its a student engineering project to show us what will happend to us when we get out working =)

Designer, though, only understands UI files and the XML they contain. It cannot ingest C++ code, and there is no tool I'm aware of that can produce UI files from such code (apart from wysota's tool, mentioned above).

You can either A) modify your existing code by hand to make it match desired appearances, or B) create a brand new GUI using Designer, then extend the Designer-produced classes and call your backend from there.

Badeand
22nd March 2011, 14:53
Ok thanks guy, I guess I will just do it by hand then, but do you know if there is any way to use custom buttons that way? I heard something about a program called Qt Quick Designer, but maby thats not it.

wysota
22nd March 2011, 15:01
Yeah, I should be able to do the translation although we might have a problem with those custom widgets of yours. It's not a show-stopper though. With a bit of manual editing it should be fine. Of course for example line #1 of your second snippet is not possible to be fully translated to ui. You'd need a default constructor for your ConnectBar widget. Note though I need to be able to run your application in order to do the translation.

Badeand
22nd March 2011, 15:08
Yeah, I should be able to do the translation although we might have a problem with those custom widgets of yours. It's not a show-stopper though. With a bit of manual editing it should be fine. Of course for example line #1 of your second snippet is not possible to be fully translated to ui. You'd need a default constructor for your ConnectBar widget. Note though I need to be able to run your application in order to do the translation.

I would love this, but unfortunately I am not allowed to share my code with anyone (I had to sign a lot of documents when I started working with this) so I guess I am on my own here, but thanks for trying to help.