PDA

View Full Version : how resize the Qwidget objects within a window



vinayaka
23rd May 2011, 06:02
hai all,
There is Qmainwindow which has 2 Qpushbuttons on the left side and Qlineedit onn the right side.I would like to get the two Qpushbuttons on the left hand side and QlineEdit resized when the QMainWindow is resized.I am novice in qt. i tried what i know but i failed. can someone help me

wysota
23rd May 2011, 06:20
Get yourself familiar with the concept of "layouts".

vinayaka
23rd May 2011, 11:07
hai wysota,
i tried but failed. i tell u what it looks like .when the window was minimized the pushbutton was on the upperright hand side of the window. when it was maximized it was not on the upper right hand side of the window, on the other hand it got stick to the previous position. the right hand side was blank.:confused:

ChrisW67
23rd May 2011, 11:13
Put your widgets into a layout or layouts. See Layout Management and Layout Examples

vinayaka
25th May 2011, 06:57
hai,
i have another problem. i have a base class A and 2 derived classes B,C. In A , there is a line Edit and 2 buttons. if we click 1st button int: entered in line edit of class A must be shown in B. if we click 2nd button it should be in C's window. what should I do?can some one tell me about multiple inheritance in detail(with simple example). ( i checked it but i didnt get it):confused:

wysota
25th May 2011, 07:18
What does your problem have to do with inheritance? Implement slots that will set values on objects and connect them to signals emitted when the buttons are clicked.

ChrisW67
25th May 2011, 07:21
If B and C inherit class A, the typical meaning of derived, then the question makes no sense. B is an A and C is an A. This has nothing to do with the number of windows displayed on screen or communication between them.

I suspect you have three completely independent windows, A, B, and C, showing some widgets. You want events in A to trigger actions in B or C. You need to read about signals and slots

Santosh Reddy
25th May 2011, 07:23
So how is that you are using the Classes A, B, and C?
Looks like you have objects of all the three classes in your problem, is it so? If yes, please review your design again.

Normally you would only need Objects (instance) of B and C (as Class A is already included in both B and C)

One important thing to note is the only objects can send signals, classes cannot send. (I agree that "class" and "object" are used almost equally in this forum replies, but it looks like from your question, you have a problem to differentiate between them)

You said Class A is base class, and Class B & Class C are derived (I assume derived from Class A). This is not multiple inheritance, this pain single class inheritance.

When you say Class A has QLineEdit and QPushButtons, then it is implies that Class B and Class C already have a QLineEdit & QPushButtons in them.

Please consider re-framing your question

http://www.cplusplus.com/doc/tutorial/inheritance/

vinayaka
25th May 2011, 07:41
yes , i have 3 independent windows.the integer entered in Ist window(A) must be shown in 2nd win:(B) when button 1 is clicked. when button 2 is clicked we must be in 3rd wi:(C) with int:.
I went through some ex: but i didn't get it. Please help me(Can you teach me ,because i only started to learn cute Qt:D)

wysota
25th May 2011, 07:44
What exactly didn't you get in the examples?

vinayaka
25th May 2011, 07:46
how we can inherit that intger when button is clicked?

Santosh Reddy
25th May 2011, 08:03
connect button's clicked() / released() signal to a slot, and in the slot read the LineEdit contents, and populate it where ever it is needed

wysota
25th May 2011, 08:15
how we can inherit that intger when button is clicked?

Try writing some code, post it here and we'll help you fill in the blanks.

vinayaka
25th May 2011, 08:29
#include "widget.h"
#include "ui_widget.h"\
#include"day25.h"

Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QString n;
n=ui->lineEdit->text();
}

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

void Widget::on_pushButton_3_clicked()
{
day25 *k=new day25;
k->show();
this->hide();

}

////////////////////////
and in day25.cpp
///////////////////////////////
#include "day25.h"
#include "ui_day25.h"
#include"widget.h"

day25::day25(Widget *parent) :
Widget(parent),
ui(new Ui::day25)
{

ui->setupUi(this);
QString n;
ui->label_2->setText(n);


}

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



i tried, i entered a value and clicked the button but 2nd page(day25)is shown with previous one's object and no value is displayed

Santosh Reddy
25th May 2011, 08:58
Just to help you figure you things, how do you expect "day25" class constructor to know about the value in you "Widget" class, you need to pass the text in the constructor parameter.

By the the way, the way you are using the widget is not the right way to do, point to review:
1. in "on_pushButton_3_clicked()" you create a new "day25" and show it, ok fine so far. why doe you hide this, if you hide this, I don;t see code to bring it back on screen, it is not brought back, it will lying in memory, used

2. once you dispaly "day25" how do you go back?

I would recommend you to go through the sample examples in the Qt documentation, try editing them and see how each change behaves, and try modifying one of the sample to beahave as you wanted. Take your time to understand.

vinayaka
25th May 2011, 11:23
i coded like this . if this is stupid forgive me okay:cool:


//////////day25.cpp
#include "day25.h"
#include "ui_day25.h"
#include "widget.h"


day25::day25(Widget *parent) :
Widget(parent),
ui(new Ui::day25)
{

ui->setupUi(this);
//int num=100;
QString qStr = QString::number(num);
ui->label_2->setText(qStr);


}

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

////////////widget.cpp
#include "widget.h"
#include "ui_widget.h"\
#include "day25.h"
//#include<QString>

Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
//QString n;
//n=ui->lineEdit->text();
QString str;
float num;
str=ui->lineEdit->text();
num=str.toInt();

}

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

void Widget::on_pushButton_3_clicked()
{
day25 *k=new day25;
k->show();
this->hide();


}

//////day25.h
#ifndef DAY25_H
#define DAY25_H

#include <QWidget>
#include "widget.h"

namespace Ui {
class day25;
}

class day25 : public Widget
{
Q_OBJECT

public:
explicit day25(Widget *parent = 0);
~day25();

private:
Ui::day25 *ui;
};

#endif // DAY25_H

/////widget.h
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
Q_OBJECT

public:
explicit Widget(QWidget *parent = 0);
~Widget();

private:
Ui::Widget *ui;

private slots:
void on_pushButton_3_clicked();
};

#endif // WIDGET_H


error:num is not declared in this scope.
if command is removed answer is always 100:confused::crying:
plz help meeeeeeeeee

wysota
25th May 2011, 13:40
Your problems are caused by your lack of understanding of C++ or even programming in general. The fact that you have a variable "x" in some place doesn't mean that another variable called "x" in a different scope will have the same value as the other one.

Santosh Reddy
25th May 2011, 13:51
Please learn some C++ (if not all) then try Qt.

vinayaka
26th May 2011, 04:52
ok, thanku. I will do it.:)