PDA

View Full Version : Why don't I have any code related to .ui in .cpp file?



ada
4th December 2010, 14:50
Hi, I am really new in Qt. I created a GUI application project and I am trying to edit the buttons I created in the Designer but where are they created in the code? I can't see anything related to it in .cpp files. I assumed that it would be like Visual Studio you know when I double click on sth I can write the events of it etc. In my mainwindow.cpp there is only

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

How do I change the buttons or anything I created with this? I have a main.cpp other than this.

ireas
4th December 2010, 15:34
The UI part is stored in the .ui xml file, e. g. mainwindow.ui (see Qt documentation). It is loaded by the ui object with the line:


ui->setupUi(this);

You are able to edit this .ui file by hand, but espacially for someone new to Qt, it is better to edit it with Qt Creator (the Qt IDE) or Qt Designer.

ada
4th December 2010, 16:12
The UI part is stored in the .ui xml file, e. g. mainwindow.ui (see Qt documentation). It is loaded by the ui object with the line:


ui->setupUi(this);

You are able to edit this .ui file by hand, but espacially for someone new to Qt, it is better to edit it with Qt Creator (the Qt IDE) or Qt Designer.

How do I handle the events by hand like Visual Studio with C#? I want to be able to change one panel with button clicks, how can I handle it? The other parts of the page should remain the same like Facebook (only the middle area changes by clicking buttons etc.)

Zlatomir
4th December 2010, 16:50
Read about signals and slots, documentation here (http://doc.trolltech.com/4.7/signalsandslots.html).

ireas
4th December 2010, 20:21
Maybe it is helpful for you to know that all objects you create with the designer are members of the ui object. So if you create a object named lineEdit, you may access it with ui->lineEdit. Please read the Qt documentation, examples and tutorials for more information.

ada
4th December 2010, 20:29
Thank you now I am writing as ui-> etc. But I still couldn't figure out how I can change the middle part only. When I click Performance, I should get Performance Edit in the middle, when I click Home, I should get the table of some stuff. How can I manage this? Can't I do this with ui designer and then edit it? Or should I do it all in the code?

squidge
4th December 2010, 23:16
Its all done for you by uic - which takes your .ui file created by designer and generates code which it places into a header file. The code in this header file generates the ui for you.

However, you shouldn't edit this header file yourself.

What are you trying to do exactly - what do you mean by "changing the middle part only" - what middle part? We don't have the design of your ui, we have no idea of what you are talking about.

ChrisW67
5th December 2010, 01:58
Related thread with vague UI description here:
http://www.qtcentre.org/threads/36631-How-to-change-only-part-of-an-application-with-signals-button-clicked

marcvanriet
5th December 2010, 22:41
Hi Ada,

For your 'middle' part :
- open your form in the form editor
- from the controls toolbar under 'containers', add a 'Frame' on the left side of the form, a Stacked Widget in the middle, and then again a Frame on the right
- apply a Horizontal layout to the form. This arranges the 2 frames and stackedwidget in 3 colums. Adjust size properties as you like
- to the Stacked Widget, add 3 pages for home, performance, edit
- in the left frame, add 3 buttons for home, performance, edit
- add code to the 3 buttons to select the correct page in the Stacked Widget

You should be able to figure out how to do each of these steps by yourself.

Best regards,
Marc