Layering of widgets.please help me out
-
i have created 3 different layers of widgets on main window through drag and drop in ui and promoted all three widgets to different claases.now i have drawn 3 ellipses on three different widgets .there are 3 pushbuttons and i want on click of each button circles disappear respectively.
i am sending my code.please help me.its urgent.h
@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}class MainWindow : public QMainWindow //class mainwindow
{
Q_OBJECTpublic:
bool m_flag;
bool m_increment;MainWindow(QWidget *parent = 0); ~MainWindow();
private:
Ui::MainWindow *ui;private slots:
private slots:
void on_pushButton_3_clicked();
//void on_pushButton_2_clicked();
void on_pushButton_clicked();
};class mywidget : public QWidget // class mywidget
{
Q_OBJECTpublic:
mywidget(QWidget *parent = 0);
void paintEvent(QPaintEvent *);
public slots:
private:
Ui::MainWindow *ui;private slots:
};
class mywidget2 : public QWidget // class mywidget2
{
Q_OBJECTpublic:
mywidget2(QWidget *parent = 0);
void paintEvent(QPaintEvent *event);
private:
Ui::MainWindow *ui;private slots:
};
class mywidget3 : public QWidget // class mywidget2{
Q_OBJECTpublic:
mywidget3(QWidget *parent = 0);
void paintEvent(QPaintEvent *eve);
private:
Ui::MainWindow *ui;private slots:
};
#endif // MAINWINDOW_H
@.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPainter.h>int x=00;
int y=00;
int w=529;
int h=569;MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{m_flag=false;
m_increment=false;ui->setupUi(this);
//creating widget on ui
//connect(ui->pushButton_3,SIGNAL(clicked()),wid,SLOT(button()));//connecting plot tfu button with widget
}
MainWindow::~MainWindow()
{
delete ui;
}
mywidget::mywidget(QWidget *parent)
: QWidget(parent)
{
}mywidget2::mywidget2(QWidget *parent)
: QWidget(parent)
{}
mywidget3::mywidget3(QWidget *parent)
: QWidget(parent)
{}
void mywidget ::paintEvent(QPaintEvent *)
{// dimensions of plotting window
int x=00;
int y=00;
int w=529;
int h=569;QPainter painter(this);
QRectF rect(x,y,w,h);
painter.drawEllipse(rect);QPainter paint(this);
paint.setViewport(x,y,w,h);
paint.setWindow(-w/2,-h/2,w,h);
paint.scale(1,-1);paint.setPen(QColor::QColor(255,128,0,255));
paint.drawLine((w)/2,0,-(w)/2,0);
paint.drawLine(0,-(h)/2,0,(h)/2);}
void mywidget2 ::paintEvent(QPaintEvent *event)
{
int x=00;
int y=00;
int w=529;
int h=569;
QPainter painter(this);
QRectF rect(130,130,w/2,h/2);painter.drawEllipse(rect);
QPainter paint(this);
paint.setViewport(x,y,w,h);
paint.setWindow(-w/2,-h/2,w,h);
paint.scale(1,-1);}
void mywidget3 ::paintEvent(QPaintEvent *eve)
{int x=00;
int y=00;
int w=529;
int h=569;
QPainter painter(this);QRectF rectangle(180,180,w/3,h/3);
painter.drawEllipse(rectangle);QPainter paint(this);
paint.setViewport(x,y,w,h);
paint.setWindow(-w/2,-h/2,w,h);
paint.scale(1,-1);}
void MainWindow::on_pushButton_clicked()
{
if( m_flag=true)
{
ui->widget_3->enabled(false);}
}
void MainWindow::on_pushButton_3_clicked()
{
if (m_flag=true)
{ui->widget_2->enabled(false); }
}
@[[Added code tags, Tobias]]
-
first thing to do: USE CODE TAGS!
-
ok.i will be sure next time tu use code tags.as i have just recently joined this group so was not aware of this.
thanx -
in the slots instead of calling enabled() call:
@
ui->widget_2->setVisible( ! ui->widget_2->isVisible() ); //this will toggle visibility
@ -
in my code instead of enabled (false),it was hide().i wrote it by mistake.
thanx for suggesting me ,but i tried your code,it is doing the same thing as my hide function.when i press my pushbutton3,i want that only the second ellipse got disappear and remaining figure remains same.but as i applied your code it hides both my inner circle as both of my widgets are hiding.and when i apply my hide function to widget1,all of my widgets are hiding..
as i am new to Qt please suggest me the right way with changes in a code..
once again thanx for your help -
ok, this means that e.g. widget2 is a child of widget1. So it's normal behavior that a parent widget also hides it's child widgets.
You need to ensure that all widgets have the same parent, then your code will work. I can't help you with that because i never used Qt Designer to build up a GUI. But i'm sure it provides options for such a simple task. -
thanks a lot for your suggestion.but i believe there is a silly mistake in the code but i am not able to find that where i am going wrong..
i hope sooner you could find a solution for this as i have to complete my project and this is just the beginning..... -
thanx raven .thanx a lot .i tried in my ui and found that all widgets were having a common parent so i resolved that issue and appllied ur code again.and it worked perfectly...
thanx .
please send me your email id .in future also if i will be having any issues related qt will ask you only raven... -
[quote author="sidharth" date="1368611482"]
please send me your email id .in future also if i will be having any issues related qt will ask you only raven...[/quote]
No :)
Keep using the forums. Since this way it may help others with the same problem and also more people are reading it. -
i am new in qt . i have created 3 layers of widget on mainwindow.now i want to set the coordinates system such that my (0,0) got set on centre of widget and accordingly follows coordinate system.
i dont want to use set viewport or setwindow functions because these functions use QPainter and i dont want to use qpainter.
i want that once i set my coordinates system i need not to set it again nd again..please help me outany help will be appreciated