ayanda83
11th April 2015, 06:10
Hi guys, I have four QGraphicsItems that are stacked one on top of the other using the zValue. Each QGraphicsItem is the same size as the scene rect, so I can only display one item at a time. These QGraphicsItems are basically a rectangle with a white background for me to paint over. Each item is hidden using the hide() function except the one with the highest zValue. My problem is that I want to be able to display each of these pages at the click of a button by changing the zValue of the QGraphicsItem that I want to display to a high zValue and then showing the item using the show() function but my code below crashes my program.
void MainWindow::on_nextBtn_clicked()
{
if(pageIterator <= 3){
pagesList.at(pageIterator)->hide();
pageIterator++;
pagesList.at(pageIterator)->show();
}
}
I loaded all the pages (i.e. the QGraphicsItems) into a QList (i.e.
pagesList) and the page at
pagesList.at(0) is the first page that loaded on program start-up. The variable
pageIterator is a static variable that is initialized to zero and its sole purpose is to keep track of which page is displayed on screen. You will notice that nowhere in my code am I changing the zValue, its because I tried playing around with it and it also crashed my program. Can somebody suggest something, I am bit stuck here.
void MainWindow::on_nextBtn_clicked()
{
if(pageIterator <= 3){
pagesList.at(pageIterator)->hide();
pageIterator++;
pagesList.at(pageIterator)->show();
}
}
I loaded all the pages (i.e. the QGraphicsItems) into a QList (i.e.
pagesList) and the page at
pagesList.at(0) is the first page that loaded on program start-up. The variable
pageIterator is a static variable that is initialized to zero and its sole purpose is to keep track of which page is displayed on screen. You will notice that nowhere in my code am I changing the zValue, its because I tried playing around with it and it also crashed my program. Can somebody suggest something, I am bit stuck here.