[PyKDE] Implement MailTo in QT

Keo Sophon keosophon at khmeros.info
Thu Nov 16 10:23:37 GMT 2006


On Wednesday 15 November 2006 16:36, Andreas Pakulat wrote:
> On 15.11.06 10:18:54, Keo Sophon wrote:
> > I have an about dialog which has author email links. When a user clicks
> > on those links, it will automatically open a default mail-client. Do you
> > know how to implement the code of it? Or do you know any widget and
> > property of that widget that I can use to implement?
>
> With Qt4.2 you could use QDesktopServices and run openUrl with
> mailto:foobar at somename.com.
>
> With Qt4.1/Qt3 you have to write platform-dependent code.
>
> Andreas

I am using Qt4.1. The problem has been solved already. The following is part 
of code:

import sys
from PyQt4 import QtCore, QtGui

class AuthorsTab(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)        
        fileNameLabel = QtGui.QTextBrowser()
        fileNameLabel.setHtml(self.tr('<br>Hok Kakada (<a 		z	
href="mailto:hokkakada at khmeros.info">hokkakada at khmeros.info</a>)<br><br>Keo 
Sophon (<a 
href="mailto:keosophon at khmeros.info">keosophon at khmeros.info</a>)<br><br>San 
Titvirak (<a 
href="mailto:titvirak at khmeros.info">titvirak at khmeros.info</a>)<br><br>Seth 
Chanratha(<a 
href="mailto:sethchanratha at khmeros.info">sethchanratha at khmeros.info</a>)'))                    
	
	self.connect(fileNameLabel, QtCore.SIGNAL("anchorClicked(const 
QUrl&)"),self.handleLinkClicked)
        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(self.fileNameLabel)
        self.setLayout(mainLayout)

	def handleLinkClicked(self, url):
        '''slot to handle when anchorClicked (an email address), and open a 
webbrowser and a mail client'''
        self.sender().setSource(QtCore.QUrl())
        try:
            import webbrowser
            webbrowser.open(unicode(url.toString()))
            return
        except:
            pass

Thanks.
Phon




More information about the PyQt mailing list