Results 1 to 4 of 4

Thread: Return to MainWindow

  1. #1
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default Return to MainWindow

    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:

    Qt Code:
    1. def openNotePad(self):
    2. self.textEdit = QtGui.QTextEdit()
    3. self.setCentralWidget(self.textEdit) #This line
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. self.setCentralWidget(Window()) #Goes to the original Window screen
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Return to MainWindow

    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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Drama (16th January 2016)

  4. #3
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default Re: Return to MainWindow

    Well i fixed as i was explaining it to you haha.

    Im gonna leave it here in case anyone needs it:


    Quote Originally Posted by anda_skoa View Post
    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
    Last edited by Drama; 16th January 2016 at 23:55.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Return to MainWindow

    Quote Originally Posted by Drama View Post
    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,
    _

Similar Threads

  1. Replies: 3
    Last Post: 16th April 2015, 21:49
  2. How to return a QFile ?
    By oldFox64 in forum Newbie
    Replies: 7
    Last Post: 7th February 2014, 15:02
  3. Replies: 1
    Last Post: 2nd January 2013, 09:48
  4. Replies: 0
    Last Post: 6th November 2011, 09:22
  5. Replies: 1
    Last Post: 12th April 2011, 09:53

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.