View Full Version : accessing widgets in the source code
franco.amato
14th January 2010, 23:21
Hi,
I'm just learning Qt designer.
I installed the Qt plugin to create a new Qt project in visual studio.
I created a simple gui with designer dragging some widgets.
In the generated code there is a
ui.setupUi(this); routine.
Seems that every time I have to access to some of the qt widgets by code I have to prepend the "ui." prefix or I'm doing something wrong?
For example with designer I dragged on the form a QLabel, then I called it label.
If I would call some of the QLabel methods I have to write ui.label->setText( bla bla ) ?
Or the is something wrong in my logic? I don't like the idea of write ui. before every widget.
I hope to be wrong.
Best
squidge
15th January 2010, 08:06
The idea is encapsulation - all ui objects belong to an object called 'ui' so you don't mix them with your non-ui objects.
However, if you prefer them mixed, you can always use multiple inheritance.
If you don't know how to do that, an example is here: http://doc.trolltech.com/4.3/uitools-multipleinheritance.html
viper
18th January 2010, 16:21
with regards to the original question, I have the same problem but i don't mind typing the ui. The only true problem i have is that i don't see the widgets eg lable in the header file, when i use qt 4.is there anyway to get them in the header or source file constructor, so i can see all the variable/widgets on a form?
squidge
18th January 2010, 17:42
I don't get what you mean. All widgets are in the appropriate header file in the 'ui' namespace.
viper
19th January 2010, 05:20
#ifndef DIALOG_H
#define DIALOG_H
#include <QtGui/QDialog>
namespace Ui
{
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
private:
Ui::Dialog *ui;
};
#endif // DIALOG_H
This is the header file for a form I created using Qt 4 creator, on the form i have two push Button and a Lable, in the ui file, but none of the widgets are shown in the header file, nor the source file. Please help, i am using qt 4 creator,
wysota
19th January 2010, 11:08
This is the header file for a form I created using Qt 4 creator,
No, this is a header file for a widget.
on the form i have two push Button and a Lable, in the ui file, but none of the widgets are shown in the header file, nor the source file.
As you said yourself - they are in the ui file (or the file generated from it to be precise, it's called ui_nameofyouruifile.h).
viper
19th January 2010, 15:00
Thanks a lot for your help, I search for the file you mentioned and found it, The thing is i was viewing the project files, so i just change the view to file system. sorry for posting in here
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.