Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display Math symbols in a QLabel
Forum Updated to NodeBB v4.3 + New Features

Display Math symbols in a QLabel

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 25.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gworouge
    wrote on last edited by
    #1

    Hi,

    I can't find some information about how to display math symbolic expression in a Qlabel.

    for example, how to display the mathematical symbol "alpha" instead of the word "alpha" ?

    the math symbol "square root" instead of "sqrt" and so on ? ...

    many thanks for any help you could bring

    Gwo

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      QLabel supports Unicode:
      "Math Operators":http://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode
      "Mathemathical Alphanumeric Symbols":http://en.wikipedia.org/wiki/Mathematical_alphanumeric_symbols_Unicode_block

      Of course you won't be able to display complex Mathematical expressions. For that you could use something like "this":http://doc.qt.nokia.com/solutions/4/qtmmlwidget/qtmmlwidget.html

      EDIT: fixed link

      EDIT2: "Source Code":ftp://ftp.qt.nokia.com/qt/solutions/lgpl/

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3

        I have used the qmmlwidget before and it worked well from what I can recall. Just a shame that mml is so verbose. I dream of a text layout system for Qt that could render LaTeX.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          That would be ideal

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gworouge
            wrote on last edited by
            #5

            Thank you for those information.

            my Gui doesn't show what I would like to see; can you tell me where I make a mistake ?

            I have two files : init.py which calls untitled.py :

            init.py :
            @# -- coding: utf-8 --

            """The user interface for our app"""

            import os,sys

            Import Qt modules

            from math import *
            from PyQt4 import QtCore, QtGui
            from PyQt4.QtGui import *
            from PyQt4.Qt import *

            from untitled import *

            Create a class for our main window

            class Main(QtGui.QMainWindow):
            def init(self):
            QtGui.QMainWindow.init(self)

                # This is always the same
                self.ui=Ui_MainWindow()
                self.ui.setupUi(self)
            

            def main():
            # Again, this is boilerplate, it's going to be the same on
            # almost every app you write
            app = QtGui.QApplication(sys.argv)
            window=Main()
            window.show()
            # It's exec_ because exec is a reserved word in Python

            sys.exit(app.exec_())
            

            if name == "main":
            main()

            @

            and untitled.py :
            @# -- coding: utf-8 --

            Form implementation generated from reading ui file 'untitled.ui'

            Created: Sun Jun 19 11:26:12 2011

            by: PyQt4 UI code generator 4.8.4

            WARNING! All changes made in this file will be lost!

            from PyQt4 import QtCore, QtGui

            try:
            _fromUtf8 = QtCore.QString.fromUtf8
            except AttributeError:
            _fromUtf8 = lambda s: s

            class Ui_MainWindow(object):
            def setupUi(self, MainWindow):
            MainWindow.setObjectName(_fromUtf8("MainWindow"))
            MainWindow.resize(721, 502)
            self.centralwidget = QtGui.QWidget(MainWindow)
            self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
            self.label = QtGui.QLabel(self.centralwidget)
            self.label.setGeometry(QtCore.QRect(80, 110, 441, 31))
            self.label.setObjectName(_fromUtf8("label"))
            MainWindow.setCentralWidget(self.centralwidget)
            self.menubar = QtGui.QMenuBar(MainWindow)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 721, 20))
            self.menubar.setObjectName(_fromUtf8("menubar"))
            MainWindow.setMenuBar(self.menubar)
            self.statusbar = QtGui.QStatusBar(MainWindow)
            self.statusbar.setObjectName(_fromUtf8("statusbar"))
            MainWindow.setStatusBar(self.statusbar)

                self.retranslateUi(MainWindow)
                QtCore.QMetaObject.connectSlotsByName(MainWindow)
            
            def retranslateUi(self, MainWindow):
                str_swt = QtCore.QString(U'\221A')
                MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
                self.label.setText(QtGui.QApplication.translate("MainWindow", str_swt, None, QtGui.QApplication.UnicodeUTF8))
            

            class Main(QtGui.QMainWindow):
            def init(self):
            QtGui.QMainWindow.init(self)

                # This is always the same
                self.ui=Ui_MainWindow()
                self.ui.setupUi(self)
            

            def main():
            # Again, this is boilerplate, it's going to be the same on
            # almost every app you write
            app = QtGui.QApplication(sys.argv)
            window=Main()
            window.show()
            # It's exec_ because exec is a reserved word in Python

            sys.exit(app.exec_())
            

            if name == "main":
            main()
            @

            Thanks again

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gworouge
              wrote on last edited by
              #6

              Sorry, there has been some code copied at the end of untitled.py; here it is again :
              @# -- coding: utf-8 --

              Form implementation generated from reading ui file 'untitled.ui'

              Created: Sun Jun 19 11:26:12 2011

              by: PyQt4 UI code generator 4.8.4

              WARNING! All changes made in this file will be lost!

              from PyQt4 import QtCore, QtGui

              try:
              _fromUtf8 = QtCore.QString.fromUtf8
              except AttributeError:
              _fromUtf8 = lambda s: s

              class Ui_MainWindow(object):
              def setupUi(self, MainWindow):
              MainWindow.setObjectName(_fromUtf8("MainWindow"))
              MainWindow.resize(721, 502)
              self.centralwidget = QtGui.QWidget(MainWindow)
              self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
              self.label = QtGui.QLabel(self.centralwidget)
              self.label.setGeometry(QtCore.QRect(80, 110, 441, 31))
              self.label.setObjectName(_fromUtf8("label"))
              MainWindow.setCentralWidget(self.centralwidget)
              self.menubar = QtGui.QMenuBar(MainWindow)
              self.menubar.setGeometry(QtCore.QRect(0, 0, 721, 20))
              self.menubar.setObjectName(_fromUtf8("menubar"))
              MainWindow.setMenuBar(self.menubar)
              self.statusbar = QtGui.QStatusBar(MainWindow)
              self.statusbar.setObjectName(_fromUtf8("statusbar"))
              MainWindow.setStatusBar(self.statusbar)

                  self.retranslateUi(MainWindow)
                  QtCore.QMetaObject.connectSlotsByName(MainWindow)
              
              def retranslateUi(self, MainWindow):
                  str_swt = QtCore.QString(U'\221A')
                  MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
                  self.label.setText(QtGui.QApplication.translate("MainWindow", str_swt, None, QtGui.QApplication.UnicodeUTF8))
              

              @

              1 Reply Last reply
              0
              • L Offline
                L Offline
                loladiro
                wrote on last edited by
                #7

                I have so far not seen a string literal that consited directly of unicode chars but rather something like this (c++, python should be similar):
                @
                str1 = QString(QChar(0x221A));
                str2 = QString("This is my very second unicode string: %1").arg(QChar(0x221A));
                @

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gworouge
                  wrote on last edited by
                  #8

                  hello loladiro,

                  all I can see is a "?" but not any alpha symbol (unicode u221A...).

                  if you have a chance, please copy paste and run the two files init.py :
                  @# -- coding: utf-8 --

                  """The user interface for our app"""

                  import os,sys

                  Import Qt modules

                  from math import *
                  from PyQt4 import QtCore, QtGui
                  from PyQt4.QtGui import *
                  from PyQt4.Qt import *

                  from untitled import *

                  Create a class for our main window

                  class Main(QtGui.QMainWindow):
                  def init(self):
                  QtGui.QMainWindow.init(self)

                      # This is always the same
                      self.ui=Ui_MainWindow()
                      self.ui.setupUi(self)
                  

                  def main():
                  # Again, this is boilerplate, it's going to be the same on
                  # almost every app you write
                  app = QtGui.QApplication(sys.argv)
                  window=Main()
                  window.show()
                  # It's exec_ because exec is a reserved word in Python

                  sys.exit(app.exec_())
                  

                  if name == "main":
                  main()
                  @

                  and untitled.py :

                  @# -- coding: utf-8 --

                  Form implementation generated from reading ui file 'untitled.ui'

                  Created: Sun Jun 19 11:26:12 2011

                  by: PyQt4 UI code generator 4.8.4

                  WARNING! All changes made in this file will be lost!

                  from PyQt4 import QtCore, QtGui

                  try:
                  _fromUtf8 = QtCore.QString.fromUtf8
                  except AttributeError:
                  _fromUtf8 = lambda s: s

                  class Ui_MainWindow(object):
                  def setupUi(self, MainWindow):
                  MainWindow.setObjectName(_fromUtf8("MainWindow"))
                  MainWindow.resize(721, 502)
                  self.centralwidget = QtGui.QWidget(MainWindow)
                  self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
                  self.label = QtGui.QLabel(self.centralwidget)
                  self.label.setGeometry(QtCore.QRect(80, 110, 441, 31))
                  self.label.setObjectName(_fromUtf8("label"))
                  MainWindow.setCentralWidget(self.centralwidget)
                  self.menubar = QtGui.QMenuBar(MainWindow)
                  self.menubar.setGeometry(QtCore.QRect(0, 0, 721, 20))
                  self.menubar.setObjectName(_fromUtf8("menubar"))
                  MainWindow.setMenuBar(self.menubar)
                  self.statusbar = QtGui.QStatusBar(MainWindow)
                  self.statusbar.setObjectName(_fromUtf8("statusbar"))
                  MainWindow.setStatusBar(self.statusbar)

                      self.retranslateUi(MainWindow)
                      QtCore.QMetaObject.connectSlotsByName(MainWindow)
                  
                  def retranslateUi(self, MainWindow):
                      strswt = QtCore.QString("This is my very second unicode string: %1").arg(QtCore.QChar(0x221A))
                      MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
                      self.label.setText(QtGui.QApplication.translate("MainWindow", QtCore.QString(strswt), None, QtGui.QApplication.UnicodeUTF8))
                  

                  @

                  thanks for your patience and help.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bruceoutdoors
                    wrote on last edited by
                    #9

                    [quote author="ZapB" date="1308484736"]I have used the qmmlwidget before and it worked well from what I can recall. Just a shame that mml is so verbose. I dream of a text layout system for Qt that could render LaTeX.[/quote]

                    There is the KLFBackend library that renders LaTeX code, if I think that's what you're dreaming of:
                    http://qt-project.org/wiki/Qt_and_LaTeX_via_KLFBackend

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved