Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: QTextCharFormat::setAnchorHref() частично не работает
Форум на CrossPlatform.RU > Библиотеки > Qt > Qt GUI
qt4flanker
Применение функции QTextCharFormat::setAnchorHref() не делает текст синим и подчёркнутым, хотя тэг <a> добавляется корректно (что видно по qDebug() << textEdit->toHtml()).
Чтобы изменения вступили в силу (т.е. текст стал синим и подчёркнутым), приходится перезагружать документ (textEdit->setHtml(textEdit->toHtml()).

// QTextCharFormat::setAnchorHref() does not work properly.
// When we select the text and apply setAnchorHref() the
// text format does not change to blue-colored, underlined.
// But QTextEdit::toHtml() show the presence of <a...> tag.
// To update text format we have to reload the document as:
// textEdit->setHtml(textEdit->toHtml())

// WinXP X64 (SP2) EN + Qt4.6.2 + Qt Creator 1.3.1 +
// gcc4.4 (from ftp://ftp.qt.nokia.com/misc/MinGW-gcc440_1.zip)

#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QTextEdit* textEdit = new QTextEdit;
    textEdit->setHtml("Hello World!");
    textEdit->show();

    textEdit->selectAll();
    QTextCharFormat fmt = textEdit->currentCharFormat();
    fmt.setAnchor(true);
    fmt.setAnchorHref("http://qt.nokia.com/");
    textEdit->setCurrentCharFormat(fmt);

    qDebug() << textEdit->toHtml(); // there is <a href=... > tag in the debug output,
    // but the text format does not change to blue-colored, underlined.

    // if we uncomment the next line of code the hyperlink will be formatted properly
//    textEdit->setHtml(textEdit->toHtml());

    return a.exec();
}


Прошу пользователей форума посмотреть, повторяется ли у них этот баг или нет.
anonimus
Аналогичная проблема. Просьба знатокам откликнуться.
Zifix
Ответ: в документации написано недостаточно четко, они и не должны синеть. Для этого просто подсвечиваем руками задавая подчеркивание и цвет.

https://github.com/mipt-ilab/mipt-vis/issues/55
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.