Results 1 to 2 of 2

Thread: selecting that single character..

  1. #1
    Join Date
    Jul 2010
    Posts
    63
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default selecting that single character..

    so i want to highlight matching parenthesis/braces.

    i got a it working, but i cant seem to make it select a single character. i managed to highlight the entire line however, so I'm on the right track.

    whenever textCursor position changes, i check if the character is for instance a closing brace. i use a method i wrote to find the 'twin' and add them to the extra selection.

    problem is i just cant find a different way to have this work (the selection) other than 'QTextFormat::FullWidthSelection'. i want to highlight the specific character, but doing so in the highlighter would be too unnecessarily complicated..

    Qt Code:
    1. QList<QTextEdit::ExtraSelection> extraSelections;
    2.  
    3. QTextEdit::ExtraSelection selection;
    4.  
    5. if( document()->characterAt(textCursor().position()-1) =='}')
    6. {
    7. selection.format.setBackground(QColor(Qt::green));
    8. selection.cursor = textCursor();
    9. selection.cursor.setPosition(findTwinBehind());
    10. selection.format.setProperty(QTextFormat::FullWidthSelection, true);
    11. selection.cursor.clearSelection();
    12. extraSelections.append(selection);
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2010
    Posts
    63
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: selecting that single character..

    this worked:
    Qt Code:
    1. selection.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 1);
    To copy to clipboard, switch view to plain text mode 

    however, weirdness occurs:
    if i set a background color, all is well. if a i set a foreground color it colors the original character i set out from.. why ?
    Last edited by jajdoo; 27th July 2010 at 21:22.

Similar Threads

  1. Selecting a QLine
    By Paul Drummond in forum Qt Programming
    Replies: 6
    Last Post: 2nd September 2015, 16:30
  2. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  3. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 11:25
  4. Selecting tabbed QDockwidgets
    By trskel in forum Qt Programming
    Replies: 3
    Last Post: 25th September 2007, 17:22
  5. Selecting row in QTableView
    By teS in forum Newbie
    Replies: 1
    Last Post: 15th January 2006, 11:45

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
  •  
Qt is a trademark of The Qt Company.