Results 1 to 5 of 5

Thread: Selected Record into TextEdit...

  1. #1
    Join Date
    Sep 2009
    Posts
    34
    Thanks
    28
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Selected Record into TextEdit...

    Hi guys,

    Have a bit of a problem here, the following code doesn't work properly (it doesn't copy the value of certain fields of a user-selected record unto a QTextEdit):

    Qt Code:
    1. printviewdialog *print = new printviewdialog;
    2. print->exec();
    3. //Declaring an item selection which we will use to see which row the user has selected
    4. QItemSelection selection = ui->View->selectionModel()->selection();
    5. QList<int> rows;
    6. foreach ( const QModelIndex & index, selection.indexes() ) {
    7. rows.append( index.row() );
    8. }
    9. qSort( rows );
    10. for( int i = rows.count() - 1; i >= 0; i -= 1 ) {
    11. QString name = model->record(i).value("name").toString();
    12. print->textEdit->append(name);
    13. }
    14. if (print->Accepted) {
    15. print->textEdit->print(print->printer);
    16. }
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong? Code samples would be largely appreciated.

    Thanks in advance,

    Nefastious

  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: Selected Record into TextEdit...

    If you want help, it would be good to actually provide some specific details. Statements such as "properly" and "certain fields" do not mean much.
    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. The following user says thank you to wysota for this useful post:

    Nefastious (23rd October 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    34
    Thanks
    28
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Selected Record into TextEdit...

    Well, the QTextEdit simply shows up empty and all of the fields should be copied into it (in the sample above only the value of the "name" field is copied)...

  5. #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: Selected Record into TextEdit...

    Did you inspect that "QString name" actually contains the values you want?

    I'd also use QItemSelectionModel::selectedRows() instead of that mambo-jambo with sorting indexes.
    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.


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

    Nefastious (23rd October 2009)

  7. #5
    Join Date
    Sep 2009
    Posts
    34
    Thanks
    28
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Re: Selected Record into TextEdit...

    Well, could please give me some sample code of how to use the QItemSelection::selectedRows()?

    Thanks in advance

Similar Threads

  1. How to get parent of selected item in TreeView?
    By RavenS in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2009, 13:27
  2. deleting selected headers
    By ru_core in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2008, 07:53
  3. Help text color in TextEdit
    By tho97 in forum Qt Programming
    Replies: 5
    Last Post: 26th March 2008, 08:47
  4. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02
  5. Zooming a paricular selected region
    By Kapil in forum Newbie
    Replies: 8
    Last Post: 9th May 2006, 14:41

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.