Results 1 to 3 of 3

Thread: How to get foreign text in title bars, buttons, tool tips, etc.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to get foreign text in title bars, buttons, tool tips, etc.

    In the first example program I see:
    # -*- coding: utf-8 -*-
    I assume that this means that the encoding is UTF-8. (No?)
    No, it means that the Python interpreter should assume the file is UTF-8 encoded and not strip out non-ASCII. You must ensure that the file is saved that way. If you are editing the file with emacs that same magic line will set the editor to the relevant mode. If you edit it with something else then you must ensure that is loads/saves text UTF-8 encoded and not, for example, using Latin 1 or a Windows-1252 (which will mangle the content).

    Then you must tell Python to create Unicode strings from the string literals:
    Qt Code:
    1. # These options all work for me
    2. w.setWindowTitle(u'Простой') # note the preceding 'u'
    3. w.setWindowTitle('Простой'.decode('utf-8'))
    4. w.setWindowTitle(unicode('Простой', 'utf-8'))
    To copy to clipboard, switch view to plain text mode 
    and PyQt will do the correct thing with them.

    Generally these fixed strings would be handled using Qt's translation mechanisms.

  2. The following user says thank you to ChrisW67 for this useful post:

    tom.hedden (8th May 2014)

Similar Threads

  1. Replies: 6
    Last Post: 6th February 2013, 07:28
  2. Replies: 1
    Last Post: 4th December 2011, 14:58
  3. docked widgets and custom title bars
    By GrahamLabdon in forum Newbie
    Replies: 0
    Last Post: 16th March 2011, 09:12
  4. Grouping of Tool buttons in Tool bar
    By febil in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2009, 11:51
  5. Tool Buttons...
    By csvivek in forum Qt Tools
    Replies: 1
    Last Post: 9th May 2008, 07:44

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
  •  
Qt is a trademark of The Qt Company.