Display Math symbols in a QLabel
-
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
-
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_blockOf 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/
-
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 Pythonsys.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: sclass 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 Pythonsys.exit(app.exec_())
if name == "main":
main()
@Thanks again
-
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: sclass 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))
@
-
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));
@ -
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 Pythonsys.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: sclass 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.
-
[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