Results 1 to 8 of 8

Thread: Highlight text in list box

  1. #1
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Highlight text in list box

    Hi....

    I want to Hightlight the text in the list box when i receive a particular message.
    i want to scroll the list box without using the up/ down arrow or without clicking on the list box . this is to be done when i get a message.

    when i get a message which says Next , then i need to scroll up.

    how do i do this??

    how do i make a default selection in the List Box???

    plz help, i need this urgent....

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Highlight text in list box


  3. #3
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Highlight text in list box

    I am using QListView . will setCurrentItem() work for it?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Highlight text in list box

    Since you wrote 'list box' I thought you meant Qt3.
    Since QListView doesn't have setCurrentItem() it wont work.
    In Qt4 the model-view approach is used much more then in Qt3.
    I didn't have a chance to wrok with it yet under Qt4 - but from what I have read so far, i think you should use the selction model.
    QItemSelectionModel::select ()
    And this might be helpful as well: http://doc.trolltech.com/4.2/model-view-selection.html

  5. #5
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Highlight text in list box

    I did that the following way:

    QListViewItem *current = listview->currentItem();

    QListViewItem *after = current->itemAbove(); OR itemBelow()
    after->setSelected(TRUE);

    this way it is working.....i am able to highlight the next item in the list whenever i get a particular signal.

  6. #6
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Highlight text in list box

    I guess my question fits this thread, but solution given in last post I think isn't apropriate for Qt4.
    So, what exactly I want to do. I have a widget with QListView, QDirModel and QSelectionModel and actually I want the widget to remember activated directory, so when I come back cursor/highlighting will be on that directory.
    Example:
    we have following items in current dir:
    . .. pics walls sample.png pict.jpg
    What is default: Key_Down x 3 /*go to pics*/, Key_Return, ... , <go to "..">, enter, Key_Down x 4 /*go to walls*/, enter.
    What I want: Key_Down x 3 /*go to pics*/, enter, ..., <go to "..">, enter, Key_Down x 1 /*go to walls*/, enter.

    setCurrentIndex() doesn't work, it sets but doesn't highlight that. And you can then press Key_{Return,Enter} (btw are they equal? I know that they have different values, but anyway...) and activate it, but if you press Key_Down you will be at "."

    How to solve the problem? I don't need the full code for this =) but just wanna know how to set position of List View cursor.

    offtopic
    How to get rid of "." item, but keep ".."? I know about QDir::NoDotAndDotDot, but what about QDir::NoDot ?

    updated
    Ok, found this in QListWidget::setItemSelected(const QListWidgetItem *item, bool select)
    Qt Code:
    1. if (d->selectionMode == SingleSelection) {
    2. selectionModel()->select(index, select
    3. ? QItemSelectionModel::ClearAndSelect
    4. : QItemSelectionModel::Deselect);
    5. }
    To copy to clipboard, switch view to plain text mode 
    But when I come into /home/eruart/imgs code:
    Qt Code:
    1. selmodel->select(dirmodel->index("/home/eruart/imgs/example.png"), QItemSelectionModel::ClearAndSelect);
    To copy to clipboard, switch view to plain text mode 
    gives me following in console:
    intersectingStaticSet: row 11 was invalid
    intersectingStaticSet: row 12 was invalid

    What does it mean?
    update 2
    Qt Code:
    1. static QModelIndex last;
    2. if (!dirmodel->fileName(current).contains("..")) last = current;
    3. qDebug() << last;
    4. listview->selectionModel()->select(last,QItemSelectionModel::ClearAndSelect);
    To copy to clipboard, switch view to plain text mode 
    current here is const QModelIndex & that passed by listview's activated signal, and this code is handleActivated slot that connected with the signal.
    Qt Code:
    1. QModelIndex(4,0,0x80984a8,QDirModel(0x8082aa8) )
    2. intersectingStaticSet: row 11 was invalid
    3. intersectingStaticSet: row 12 was invalid
    4.  
    5. ~/imgs $ ls -a | wc
    6. 11 12 135
    To copy to clipboard, switch view to plain text mode 
    Why rows 11 and 12, but not 4?
    Last edited by Eruart; 7th April 2007 at 22:14. Reason: updated contents

  7. #7
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Highlight text in list box

    And now I am completely confused. I have removed all selecting code and those messages with intersectingStaticSet continue to appear.

    updated
    Hm, I recompiled with Qt4.3beta (was 4.2.3) and those messages disappeared.

    But selecting still doesn't work.
    Last edited by Eruart; 8th April 2007 at 09:28. Reason: updated contents

  8. #8
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Highlight text in list box

    I'll answer by myself, in case if someone will need it. It's far from ideal, but works for me.
    Qt Code:
    1. unsigned int lastrow;
    2.  
    3. kivBrowser::kivBrowser()
    4. {
    5. ...
    6. QStringList nameFilters;
    7. nameFilters << "??*" << ".." ;// FIX ME: one char length names doesn't match
    8. dirmodel->setNameFilters(nameFilters);
    9. ...
    10. }
    11. void kivBrowser::handleActivated(const QModelIndex & current)
    12. {
    13. if (dirmodel->isDir(current))
    14. {
    15. listview->setRootIndex(current);
    16.  
    17. listview->setCurrentIndex(listview->rootIndex().child(0,0));
    18. if (!current.row()) // FIX ME: if we cd up but never was there we would select wrong item or fail to select at all.
    19. {
    20. QModelIndex last = listview->rootIndex().child(lastrow,0);
    21. listview->setCurrentIndex(last);
    22. }
    23. else lastrow = current.row();
    24.  
    25. emit dirChanged(dirmodel->filePath(current));
    26. }
    27. else
    28. emit imgChanged(dirmodel->filePath(current));
    29. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  4. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02
  5. Finding text on Text edit
    By jyoti kumar in forum Qt Programming
    Replies: 2
    Last Post: 18th May 2006, 13:20

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.