HTML tags in QLabel



  • Hi,

    i use html tags to format my textes. But sometimes it seams not to work:

    if (!ClientName.isEmpty() && !oldChannel.isEmpty() && !newChannel.isEmpty())
    	{
    		// joined my channel
    		if (newChannelID == getCurrentChannel(serverConnectionHandlerID))
    			getController(serverConnectionHandlerID)->addChatLine(QString("<font color=\"#00FFFF\">%1 <font size=\"-5\">entered from</font> %2</font>").arg(ClientName).arg(oldChannel));
    		// quit my channel
    		else if (oldChannelID == getCurrentChannel(serverConnectionHandlerID))
    			getController(serverConnectionHandlerID)->addChatLine(QString("<font color=\"#00FFFF\">%1 <font size=\"-5\">left to</font> %2</font>").arg(ClientName).arg(newChannel));
    		// somewhere else
    		else
    			getController(serverConnectionHandlerID)->addChatLine(QString("<font size=\"-5\">%1 moved from %2 to %3</font>").arg(ClientName).arg(oldChannel).arg(newChannel));
    	}
    	else if (!ClientName.isEmpty() && oldChannel.isEmpty() && !newChannel.isEmpty())
    	{
    		getController(serverConnectionHandlerID)->addChatLine(QString("%1 <font size=\"-5\">connected to</font> %2").arg(ClientName).arg(newChannel));
    	}
    

    this does not work, too

    QString("<font size=\"-5\"><%1></font> %2").arg(fromName).arg(message)
    

    The result should be
    <name> MESSAGE
    But it does not work. I'm pretty sure it's because of the <> things. So is there a way that those are displayed and ignored from the html format if they are no keywords such as font??


  • Qt Champions 2016

    Hi
    The most easy way to check such stuff is using the HTML editor
    Place a QLabel on a form, right click it and Choose Change HTML
    alt text

    Then paste your generated html code in "source" and see what it dont like
    or Try to visually create what you want and check the HTML.



  • i could fix the chat thing with that using

    &lt;
    

    But it does not work if someone has <> in his nick name

    QString("%1 <font size=\"-5\">connected to</font> %2").arg(ClientName).arg(newChannel)
    

    Any ideas about that??



  • Man Qt is that GENIUS!!!

    QString QString::toHtmlEscaped() const


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.