mayonnaise_clinic
mayonnaise_clinic

Reputation: 81

Qt: How to go back and forth between the WYSIWYG editor and C++ code?

I'm a newbie to Qt. I'm using Qt Creator and a QT Widget Project. The QT widget project comes with a WYSIWYG editor, which I think is called Qt Designer, that seems great. But I want to be able to access the C++ code that governs all of the widgets I'm using. Right now I only have access to the widget that I defined myself; for the others (things like buttons, tables, spin boxes etc) I don't know how to see their code; I can only see the XML that governs their formatting.

Also, working in reverse, I want to be able to take some of the example projects and code that I see on the internet and edit them in Qt Designer, or at least discover how to incorporate them into something I've built with it. A lot of the examples have really cool stuff going on that I would like to try, but they generally don't seem to use Qt Designer for their layouts and frankly I'm kind of mystified as to how the layout is managed in a lot of cases. I see lots of documentation on how to build this or that object, but I haven't as yet found the bridge I need to take that knowledge and add to it how to arrange the objects you've built in a layout.

So I have a little knowledge of how to program objects, and a little knowledge of how to build a layout, but not much knowledge of how to build objects within a layout or import someone else's object into a layout I built. Advice in either of these specific areas would be great, or you could give me some good starting points - I know the obvious answer is to read documentation, but Qt is so vast that it's a bit difficult to know what to look at.

Upvotes: 0

Views: 547

Answers (2)

cmannett85
cmannett85

Reputation: 22366

for the others (things like buttons, tables, spin boxes etc) I don't know how to see their code

It's called Qt's source code, and you can download it from the Qt website.

I can only see the XML that governs their formatting.

See Simon's answer.

I want to be able to take some of the example projects and code that I see on the internet and edit them in Qt Designer, or at least discover how to incorporate them into something I've built with it. A lot of the examples have really cool stuff going on that I would like to try, but they generally don't seem to use Qt Designer for their layouts and frankly I'm kind of mystified as to how the layout is managed in a lot of cases.

Many people don't use the designer much (me included), generally because it favours more static UIs. The layout is managed via QLayout derived classes, which are also represented in Qt Designer.

I know the obvious answer is to read documentation

Yes it is, and Qt's documentation is some of the finest out there. I think this particular example should help you along.

Upvotes: 1

Simon
Simon

Reputation: 1684

Qt Creator creates for every form corresponding cpp/h-files.

Each file has an object called "ui", which you use to access all your stuff on the form.

E.g. you have a Combobox called "comboBox1", you would set it to a value with

ui->comboBox1->setCurrentindex(1);

You should not modify all the moc_.cpp or ui_.h files, as they are generated by Qt.

Upvotes: 0

Related Questions