Results 1 to 5 of 5

Thread: Help message box

  1. #1
    Join Date
    Feb 2015
    Posts
    27
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Help message box

    I want to load and display a text file when help is clicked. It needs to be a fair-sized panel with a vertical scrollbar, the text should preferably but not necessarily be HTML and loaded from a disk file. The best I can do so far is this:
    Qt Code:
    1. with open(filename, 'r') as infile:
    2. result = infile.read()
    3. self.helptext = QtGui.QTextEdit()
    4. self.helptext.setHtml(result)
    5. self.helptext.setReadOnly(-1)
    6. self.helptext.resize(800, 500)
    7. self.helptext.show()
    To copy to clipboard, switch view to plain text mode 
    However, it floats on the main window and does not close if I close the main window. (Not modal?) I can make it attach to the main window and close when the main window is closed (modal?) by using QtGui.QTextEdit(self). This is not satisfactory though, as there is no 'X' on the window title bar (window decoration?) so no way of closing it. I have looked here http://pyqt.sourceforge.net/Docs/PyQt4/qtextedit.htmls for a way of adding it without success. Is there a way of doing so, or should I be using a different sort of widget? I have looked at all the widgets I can find but can't find what I want, a messagebox is not suitable for several reasons.
    Last edited by ChrisOfBristol; 1st April 2015 at 13:30.

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

    Default Re: Help message box

    A modal dialog is a dialog that prevents user interaction with the dialog's parent window.
    E.g. an error message box that needs to be acknowledged with OK.

    If you want that simply create QDialog subclass and put your content widget in that.

    Cheers,
    _

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

    ChrisOfBristol (2nd April 2015)

  4. #3
    Join Date
    Feb 2015
    Posts
    27
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help message box

    That made sense to me and was a good pointer in the right direction, I've come up with this now:
    Qt Code:
    1. def actionHelpTriggered(self):
    2. helpPanel = QtGui.QDialog()
    3. helpPanel.setModal(True)
    4. ###helpPanel.setSizeGripEnabled(False) #### doesn't work, it doesn't stop dialog panel being stretched bigger.
    5. helpPanel.setWindowTitle('Help')
    6. self.helptext = QtGui.QTextEdit(helpPanel)
    7. with open('help.html', 'r') as infile:
    8. result = infile.read()
    9. self.helptext.setHtml(result)
    10. self.helptext.setReadOnly(-1)
    11. self.helptext.resize(800, 500)
    12. helpPanel.show()
    13. helpPanel.helptext.show()
    To copy to clipboard, switch view to plain text mode 
    It does what I want, in that the dialog is modal with a title bar with an 'X' and the textEdit on top of it and a vertical slider. The dialog starts at the same size as the textEdit panel.
    ...in actionHelpTriggered
    helpPanel.helptext.show()
    AttributeError: 'QDialog' object has no attribute 'helptext'
    I don't know why I get this as the last two lines seem to work, and without them nothing shows.
    Last edited by ChrisOfBristol; 2nd April 2015 at 10:55.

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

    Default Re: Help message box

    The error is from line 13 in your snippet. QDialog does not have a member named "helptext".

    What you want instead of creating a dialog and then creating a text edit is to create a new class derived from QDialog that creates the text edit in its constructor.
    I.e. when using this dialog you only have to deal with one object.

    You might also want to call helpPanel.exec() instead of setting window modality and calling show, but you'll have to check if this is still the behavior you want.

    Cheers,
    _

  6. #5
    Join Date
    Feb 2015
    Posts
    27
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help message box

    Qt Code:
    1. helptext.show()
    To copy to clipboard, switch view to plain text mode 
    has the same effect - it causes a warning, so it's odd that it works.
    ...QDialog that creates the text edit in its constructor...
    is completely beyond my level of understanding. I'm going to stick with what I've got because at least it works.
    Last edited by ChrisOfBristol; 2nd April 2015 at 14:43.

Similar Threads

  1. error message
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2009, 14:08
  2. StatusBar Message
    By chethana in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 15:44
  3. Replies: 4
    Last Post: 12th October 2008, 13:47
  4. Send TCP message
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2008, 09:33
  5. Get Windows message
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2008, 10:28

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.