PDA

View Full Version : QtTraining-Your First Qt Application



dagobert1989
13th January 2011, 12:56
How to achive this?Can someone help me?
http://www.flickr.com/photos/58329258@N08/5351309245/
Please see the Attachments!



#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QWidget window; // our top-level window

// ... your code here

window.resize(480, 640);
window.show();

return app.exec();
}

Thankyou Very Much!

FelixB
13th January 2011, 13:00
what do you want to do?

dagobert1989
13th January 2011, 13:04
Please see the attachments.
Thanks!

FelixB
13th January 2011, 13:12
you don't want us to give you the complete code, do you?

I'd suggest:
First, you search appropriate QWidgets.
Second, you read about QLayouts.

you can ask specific questions, of course.
Felix

squidge
13th January 2011, 13:25
The easiest way to achieve that is to use Qt Designer. Select your widgets, drag them on the form and repeat until you have the same window as shown in your attachment.

Of course, it will not be functional, but then again, neither is a screenshot.

dagobert1989
13th January 2011, 14:14
Yeah.
I write some codes.But it didn't work.
Can you give me some tips?
How can I make it right.
Please tell me how.


/************************************************** ***********************
*
* Copyright (c) 2008-2011, Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
*
* See the LICENSE.txt file shipped along with this file for the license.
*
************************************************** ***********************/

#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QWidget window; // our top-level window

QLabel *itemLabel=new QLabel("Item",window);
QLineEdit *lineEdit=new QLineEdit(window);
QLabel *itemlistLabel=new QLabel("Item",window);
QPushButton *addPushButton=new QPushButton("Add",window);
QTextEdit *textEdit=new QTextEdit(window);

//widget layout
QHBoxLayout *inner=new QHBoxLayout();
inner->addWidget(itemLabel);
inner->addWidget(lineEdit);
inner->addWidget(addPushButton);
QVBoxLayout *outer=new QVBoxLayout();
outer->addWidget(inner);
outer->addWidget(itemlistLabel);
outer->addWidget(textEdit);

window.setLayout(outer);


// ... your code here

window.resize(480, 640);
window.show();

return app.exec();
}


Added after 18 minutes:

Yeah!I have done it using QtDesigner!

But how can I achieve this without QtDesigner?

Can you tell me how?

I am confused.

Lykurg
13th January 2011, 14:14
Gentle I want remind all here, that we do not solve homeworks!

Please tell us, what exactly does not work for you since we won't provide any code you can copy and paste. You might want have a look at the signals and slots mechanism of Qt.

dagobert1989
13th January 2011, 14:19
I am sorry!

Lykurg
13th January 2011, 14:24
I am sorry!

There is nothing to be sorry about. Try only to ask a precise question. Only by looking at the picture I do not see if you have problems with the layout or with a functionality.

squidge
13th January 2011, 16:52
Yeah!I have done it using QtDesigner!

But how can I achieve this without QtDesigner?Well, QtDesigner generates the code for you, so to do it without QtDesigner, you write similar code to what QtDesigner produces.... :)

If you want the buttons to do something, then you need to research signals and slots, as already suggested.

Zlatomir
13th January 2011, 17:29
The advice squidge gave you is very good.
But that code also uses some technical stuff you don't need to use, since that file is meant to be auto-generated and you are not supposed to write code just like UIC and then integrate it with the rest of your project using one of these methods (http://doc.qt.nokia.com/4.7/designer-using-a-ui-file.html)
So basically that file includes some tricks that allows the Qt programmers to keep separated the auto-generated code from the code they write.

So i would like to add that the advice squidge gave you is for those somehow advanced C++ programmers.
If you are experienced with C++ you can easy understand that file, and you can get inspiration form there, don't forget that ;)

The recommended reading for those new to Qt layouts is this (http://doc.qt.nokia.com/4.7/layout.html)
Also documentation for signals and slots (http://doc.qt.nokia.com/4.7/signalsandslots.html)

dagobert1989
14th January 2011, 07:42
The advice squidge gave you is very good.
But that code also uses some technical stuff you don't need to use, since that file is meant to be auto-generated and you are not supposed to write code just like UIC and then integrate it with the rest of your project using one of these methods (http://doc.qt.nokia.com/4.7/designer-using-a-ui-file.html)
So basically that file includes some tricks that allows the Qt programmers to keep separated the auto-generated code from the code they write.

So i would like to add that the advice squidge gave you is for those somehow advanced C++ programmers.
If you are experienced with C++ you can easy understand that file, and you can get inspiration form there, don't forget that ;)

The recommended reading for those new to Qt layouts is this (http://doc.qt.nokia.com/4.7/layout.html)
Also documentation for signals and slots (http://doc.qt.nokia.com/4.7/signalsandslots.html)

Thanks a lot,you are very kind.
I a newbie,so I don't know the signals and slots.
I am trying to understand the signals and slots by reading the documentation.
Thanks for your suggestsion.

Added after 56 minutes:

:D
I did it!
I achieve this UI without using QtDesigner!
code here:


#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QWidget window; // our top-level window
//your code here...
QLabel *itemLabel=new QLabel("Item");
QLineEdit *lineEdit=new QLineEdit();
QLabel *itemlistLabel=new QLabel("ItemList");
QPushButton *addPushButton=new QPushButton("Add");
QTextEdit *textEdit=new QTextEdit();

//widget layout
QHBoxLayout *inner=new QHBoxLayout();
inner->addWidget(itemLabel);
inner->addWidget(lineEdit);
inner->addWidget(addPushButton);
QVBoxLayout *outer=new QVBoxLayout();
outer->addLayout(inner);
outer->addWidget(itemlistLabel);
outer->addWidget(textEdit);

window.setLayout(outer);


// ... your code here

window.resize(480, 640);
window.show();

return app.exec();
}

Thanks these kind people who helped me!