PDA

View Full Version : Return to MainWindow



Drama
15th January 2016, 19:44
Hi, the thing is that i added a text editor to my app and it all works fine, except that when i try to go to another function/tool of the app it just doesn't work. The window sticks to the textEditor and i cant go anywhere else.

I know that it is because of this:


def openNotePad(self):
self.textEdit = QtGui.QTextEdit()
self.setCentralWidget(self.textEdit) #This line

So i tried to create a button that restores the app like it was before, a "Return" button, with this line:


self.setCentralWidget(Window()) #Goes to the original Window screen

But it initializes the app twice in the same window, and all the buttons are twice in the same location, like this: http://i.imgur.com/6zT9jO5.jpg

And i also tried with __init__ but it restarts in an other window. I thought that i could do "If the app is running two instances at the same time, then close one" but it would be an awful solution... How can I do this?

anda_skoa
16th January 2016, 09:29
So your application has a central widget when you set the text editor?

If so, just keep the reference to the widget and set it again when needed.

You might also want to do the same for the text edit, so that you don't create a new one every time.

Cheers,
_

Drama
16th January 2016, 21:02
Well i fixed as i was explaining it to you haha.

Im gonna leave it here in case anyone needs it:



So your application has a central widget when you set the text editor?

If so, just keep the reference to the widget and set it again when needed.

You might also want to do the same for the text edit, so that you don't create a new one every time.

Cheers,
_

What can i do to know which is the original CentralWidget when i run the app?

The only reference to it is when i click that button (self.setCentralWidget(self.textEdit)) but it says nothing about it before

____

The solution was to extract all the toolButtons-related lines of code and put it in a different function so it doesn't load again and the buttons don't duplicate. It's a very known error but im very new to pyqt :o

anda_skoa
17th January 2016, 08:52
What can i do to know which is the original CentralWidget when i run the app?

When you call self.centralWidget() it returns the current central widget.

Cheers,
_