Results 1 to 7 of 7

Thread: QTextTable is slow!

  1. #1
    Join Date
    Sep 2009
    Posts
    41
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QTextTable is slow!

    I have a string that is a few thousand characters long, and I would like to put each character of that string in its own cell of a text table. I've been trying to do this using:

    cursor = table->cellAt(i,j).firstCursorPosition();
    cursor.insertText(letter);

    but this is excruciatingly slow for anything more than maybe one hundred characters. Is there a better way of doing this?

    Thanks for your help!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextTable is slow!

    It's probably a bad idea to build such a table. What is the purpose of the table?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    41
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTextTable is slow!

    I am trying to plot multiple gene sequences. The letters in each sequence, e.g. AGTCNNAG need to be aligned in a specific way, which I have been able to achieve by setting the font to fixed-width, then printing strings padded with the appropriate number of spaces. The problem with this method is a) I don't have any way of accessing individual characters - I would like to be able to make a click-event callback for each letter, and b) I don't like the look of fixed-width fonts.

    I've started exploring the option of using QGraphicsView to display the characters. Does this seem like a reasonable option? The documentation claims that it can handle "millions" of objects very rapidly. Hopefully that means that it will be able to display a few thousand characters to the screen instantly. There is also the possibility of using the Model-View Framework, which is also brand new to me. Would this be the best option?

    Thanks for your help!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextTable is slow!

    Quote Originally Posted by Ishmael View Post
    I've started exploring the option of using QGraphicsView to display the characters. Does this seem like a reasonable option?
    Yes.

    There is also the possibility of using the Model-View Framework, which is also brand new to me. Would this be the best option?
    Model-View is fine as well but it will probably be easier for you to use Graphics View.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Posts
    41
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTextTable is slow!

    I've been trying to use QGraphicsView with limited success. Since what I would like to do involves putting characters in a table format, it seems logical to use QGraphicsGridLayout, but I'm having trouble. So far, this is what I have:

    // This works
    QGraphicsScene *scene = new QGraphicsScene(this);
    QGraphicsView *view = new QGraphicsView(scene);
    tabs->addTab(view, "graphics");
    QGraphicsTextItem *c = new QGraphicsTextItem;
    c->setPlainText("bla");
    scene->addItem(c); // WORKS, BUT DOESN'T USE LAYOUT

    // DOESN'T WORK - Why am I not allowed to create a new QGraphicsLayoutItem?
    QGraphicsGridLayout *layout = new QGraphicsGridLayout;
    QGraphicsLayoutItem *layoutItem = new QGraphicsLayoutItem;
    layoutItem->setGraphicsItem(c);
    layout->addItem(layoutItem, 0, 0);

    // DOESN'T WORK - Why not?
    layout->itemAt(0,0)->setGraphicsItem(c);

    Also, I am having trouble grasping when to use the "new" keyword. My understanding is that 'new' allocates dynamic memory, whereas a declaration without 'new' allocates static memory, which is freed as soon as the function exits. Yet in the example shown here , the scene is declared WITHOUT the use of "new", but QGraphicsGridLayout is declared WITH 'new'. Why?

    Am I barking up the wrong tree with the QGraphicsGridLayout?

    Thanks again!
    Last edited by Ishmael; 29th September 2009 at 00:54. Reason: updated contents

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextTable is slow!

    Using the layout is ok but it's not needed in your case as you won't be doing any resizing or refitting the scene.

    Here is something I crafted quickly:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv){
    4. QApplication app(argc, argv);
    5. view.setScene(&scene);
    6. QString text = "Example text";
    7. QFont font;
    8. font.setFamily("monospace");
    9. font.setPointSize(24);
    10. QFontMetrics fm(font);
    11. int x = 0;
    12. for(int i=0;i<text.size();i++){
    13. QChar ch = text.at(i);
    14. item->setText(QString(ch));
    15. item->setFont(font);
    16. scene.addItem(item);
    17. item->setPos(x, 0);
    18. item->setFlag(QGraphicsItem::ItemIsSelectable);
    19. x += fm.width(item->text())+fm.rightBearing(ch)+10; // +10 for additional spacing
    20. }
    21. view.show();
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    You can control the distances between characters by adjusting x (and "y" if you want multiple rows).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    Ishmael (29th September 2009)

  8. #7
    Join Date
    Sep 2009
    Posts
    41
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTextTable is slow!

    Wow. What can i say? This is fantastic! Thank you!

Similar Threads

  1. Qt4, slow on windows ?
    By eto.ethome.sk in forum Qt Programming
    Replies: 3
    Last Post: 28th May 2009, 00:34
  2. Why is drawText so terribly slow?
    By Ntoskrnl in forum Qt Programming
    Replies: 8
    Last Post: 1st August 2008, 19:15
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  4. QTextCursor Find QTextTable ok and !QTextImageFormat
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 12th September 2006, 16:29

Tags for this Thread

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.