You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

phani438

Beginner

  • "phani438" is male
  • "phani438" started this thread

Posts: 4

Location: banglore

Occupation: student

  • Send private message

1

Wednesday, August 17th 2011, 11:08am

inside centerl widget items accessing problem

?( I am new to qt i want to write a program with graphicsview as centrel widget in main window ... I have a graphicsscene with 4 rectitems..In the main window i have 4 buttons i want to connect these 4 buttons with that 4 rect itms for removing and adding those items to the scene ...plz some one help me i am strrugling from 2 days
THANKS FOR HELP

pele1410

Trainee

  • "pele1410" is male

Posts: 118

Location: Lafayette, LA

  • Send private message

2

Wednesday, August 17th 2011, 12:49pm

You will need some way to reference the rectitems from your MainWindow. You can then create a custom slot in your MainWindow to handle the hiding/showing.

Source code

1
2
3
4
5
6
7
8
9
10
11
//Somewhere in your initialization
connect(pushButton1, SIGNAL(clicked()), this, SLOT(show_hide_rectitem1()));
...

void MainWindow::show_hide_rectitem1()
{
   if(rectitem1->isVisible())
       rectitem1->hide()
   else
       rectitem1->show()
}


And so on for the rest of the QPushButtons and QGraphicsItems. It's not the most elegant solution by any means, but it will get the job done.
"Without imperfection, you or I would not exist." ~Stephen Hawking

Junior

Professional

  • "Junior" is male

Posts: 1,613

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

3

Thursday, August 18th 2011, 2:13pm

phani438,

I took a few minutes and created this example that shows 4 colored squares with associated push buttons for turning them on and off.
Hope this is helpful.

Attachment unzips into graphicsview_pushbutton_example.
cd into dir
qmake -project
qmake
make
Junior has attached the following file: