Results 1 to 6 of 6

Thread: Could this be a bug in QTextBrowser?

  1. #1
    Join Date
    Mar 2007
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy Could this be a bug in QTextBrowser?

    I have put together this minimal application to demonstrate a problem with custom URL's.

    Run this application and just press enter on the default text in the line edit.
    Enter another piece of text into the line edit and press enter.
    Now click the link in the QTextBrowser.
    Now add another line of text via the line edit.
    All text added after clicking the custom URL is underlined.
    Could this be a bug or am I doing something wrong?

    The complete bug test project
    http://www.winpe.com/prog/bugtest.tar.gz

    The header File
    Qt Code:
    1. #ifndef MAINWINDOWIMPL_H
    2. #define MAINWINDOWIMPL_H
    3. //
    4. #include "ui_mainwindow.h"
    5. //
    6. class MainWindowImpl : public QMainWindow, public Ui::MainWindow
    7. {
    8. Q_OBJECT
    9. public:
    10. MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    11.  
    12. public slots:
    13. void playVMi(const QUrl &url);
    14.  
    15. private slots:
    16. void returnPressed();
    17.  
    18. private:
    19. QString detectLinks(QString dataIn, QString urlType);
    20. void display(QString dataIn);
    21.  
    22. };
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    The cpp file
    Qt Code:
    1. #include <QtGui>
    2. #include <QDesktopServices>
    3.  
    4. #include "mainwindowimpl.h"
    5. //
    6. MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
    7. : QMainWindow(parent, f)
    8. {
    9. setupUi(this);
    10.  
    11. connect(leInput, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    12.  
    13. QDesktopServices::setUrlHandler("vmi", this, "playVMi");
    14. }
    15.  
    16. void MainWindowImpl::returnPressed()
    17. {
    18. if(leInput->text() != "")
    19. display(leInput->text());
    20. leInput->setText("");
    21. }
    22.  
    23. // we registerd vm:// with the URL catcher and it sends us here when a url of this type is clicked
    24. void MainWindowImpl::playVMi(const QUrl &url)
    25. {
    26. leInput->setFocus();
    27. // Normally there would be code here to act upon the URL in some way
    28. }
    29.  
    30. void MainWindowImpl::display(QString dataIn)
    31. {
    32. dataIn = detectLinks(dataIn, "http://");
    33. dataIn = detectLinks(dataIn, "mailto:");
    34. dataIn = detectLinks(dataIn, "ftp://");
    35. dataIn = detectLinks(dataIn, "vmi://");
    36. tbDisplay->append(dataIn);
    37. tbDisplay->verticalScrollBar()->setValue(tbDisplay->verticalScrollBar()->maximum());
    38. }
    39.  
    40. // Detect URL's
    41. QString MainWindowImpl::detectLinks(QString dataIn, QString urlType)
    42. {
    43. QString url;
    44. QString user;
    45. dt = QDateTime::currentDateTime();
    46. int sp[100], ep[100], y, count1, count2;
    47. count1 = -1;
    48. count2 = -1;
    49. y = 0;
    50. do // First find the link start points
    51. {
    52. count1++;
    53. sp[count1] = dataIn.indexOf(urlType, y, Qt::CaseSensitive);
    54. y = sp[count1] + 1;
    55. }
    56. while(sp[count1] > -1);
    57. count1--;
    58. if(sp[0] > -1) // if there are any start points.....
    59. {
    60. do // find the link end points
    61. {
    62. count2++;
    63. ep[count2] = dataIn.indexOf(" ", sp[count2], Qt::CaseSensitive);
    64. if(ep[count2] == -1) // if the link is the end of the text then the space will not be found....
    65. ep[count2] = dataIn.size(); // ....so set the end point to the end of the text
    66. }
    67. while(count2 <= count1);
    68. }
    69. for(int x = count1; x >= 0; x--)
    70. {
    71. url = "\">" + dataIn.mid(sp[x], ep[x] - sp[x]) + "</a>";
    72. dataIn.insert(ep[x], url);
    73. dataIn.insert(sp[x], QString("<a href=\""));
    74. }
    75. return(dataIn);
    76. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Could this be a bug in QTextBrowser?

    Ok..it seems like a bug to me.

    First, I thought your detectLinks method had a mistake, creating a link for every new text inserted, but that's not the case.

    I added a simple debug message into the lines dedicated to link creation, and it outputs nothing when I insert standard text...

    You should post on Task Tracker, I haven't noticed a bug like that, at least for QTextBrowser.

  3. #3
    Join Date
    Mar 2007
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Could this be a bug in QTextBrowser?

    The problem is definitely with the QTextBrowser, for instance if you make the folowing changes to the returnPressed function

    Qt Code:
    1. void MainWindowImpl::returnPressed()
    2. {
    3. if(leInput->text() != "")
    4. if(leInput->text().left(1) == "a")
    5. tbDisplay->append(leInput->text());
    6. else
    7. display(leInput->text());
    8. leInput->setText("");
    9. }
    To copy to clipboard, switch view to plain text mode 

    Now any lines that start with the letter 'a' are just appended to the QTextBrowser and the problem still exists.
    If you keep adding text to the QTextBrowser without ever clicking on the custom link then all is fine, but the moment you click the custom link every line of text added to the QTextBrowser from that moment onwards is underlined, any lines added after the link was added but before the link is clicked remain okay.
    I have made a bug report with Trolltech but to be honest I would have thought someone else would have come across this by now if it is a bug.

  4. #4
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Could this be a bug in QTextBrowser?

    Yes, that's definitely strange

    But maybe this bug appeared in a recent Qt release, through QTextBrowser modifications : that would explain the lack of answers...

    Guilugi.

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Could this be a bug in QTextBrowser?

    You have a lot of way to discovery link....

    via currentCharFormatChanged each click emit this signal ....
    evry link hare underline style! probe to make a link not underline ... next reload is underline ....
    && via click on lastcursor.currentFrame(); or QTextCharFormat

    basicly QTextCharFormat say all.. http://doc.trolltech.com/4.2/qtextcharformat.html

    have a look on svn xxx https://qt-webdav.svn.sourceforge.ne...v/html_editor/
    subversion.... view modus like firefox or write modus edit use context menu....


    Qt Code:
    1. void Edit_html::DoubleClick()
    2. {
    3. Eframe = false;
    4. Eimage = false;
    5. Etable = false;
    6.  
    7. lastcursor = wtext->textCursor();
    8. xytextpos = lastcursor.position(); /* int */
    9. Eframe = lastcursor.currentFrame(); /* bool */
    10. nowimage = lastcursor.charFormat().toImageFormat(); /* bool */
    11. nowtable = lastcursor.currentTable();
    12. Eimage = nowimage.isValid(); /* bool */
    13. Etable = lastcursor.currentTable(); /* bool */
    14.  
    15. if (bellavista) {
    16. return; /* on view modus not edit! nothing*/
    17. }
    18.  
    19. if (Eimage) {
    20. Image_mod_Setting(); /* open image setting */
    21. return;
    22. }
    23. if (lastcursor.currentTable()) { /* open table setting */
    24. TableSetting();
    25. return;
    26. }
    27. }
    28.  
    29. QTextCursor lastcursor;
    30. QTextImageFormat nowimage;
    31. QTextTable *nowtable;
    32.  
    33.  
    34. /*
    35. connect(wtext, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)), this, SLOT(currentCharFormatChanged(const QTextCharFormat &)));
    36. */
    37.  
    38. void Edit_html::currentCharFormatChanged(const QTextCharFormat &format)
    39. {
    40. FontChanged(format.font());
    41. /*colorChanged(format.foreground().color());*/
    42. MakealignmentChanged(wtext->alignment());
    43. }
    44.  
    45. void Edit_html::FontChanged(const QFont &f)
    46. {
    47. vol_link->setChecked(f.underline()); /* all link are underline */
    48. fontname->setCurrentIndex(fontname->findText(f.family()));
    49. fontsize->setCurrentIndex(fontsize->findText(QString::number(f.pointSize())));
    50. vol_bold->setChecked(f.bold());
    51. vol_italic->setChecked(f.italic());
    52. vol_underline->setChecked(f.underline());
    53. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Mar 2007
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation This IS a bug in QTextBrowser.

    Trolltech have confirmed that this is a bug and it is being dealt with.

    Just thought I would mention it here in case anyone else is having a similar problem.

Similar Threads

  1. QTextBrowser, how to scroll ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2006, 07:57
  2. [QT4] QtextBrowser and image size (win)
    By sebgui in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 21:01
  3. Replies: 2
    Last Post: 15th March 2006, 12:13
  4. QTextBrowser
    By sreedhar in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2006, 13:27
  5. how to adjust sizes of QTextBrowser?
    By Pan Wojtas in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 22:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.