Results 1 to 3 of 3

Thread: Parenthesis Comparision with Enter key Event

  1. #1
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Parenthesis Comparision with Enter key Event

    I want whenever open parenthesis occurs({) cursor will move to next line and four spaces ahead and this must be recursively done (means when again parenthesis occurs then cursor will again move to next line but now cursor will move eight spaces ahead ). KeyPress Enter Code is working fine but how to compare text parenthesis along with key event?

    bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    {
    if(event->type() == QEvent::KeyPress){
    QKeyEvent *key = static_cast<QKeyEvent*>(event);

    if(key && key->key() == Qt::Key_Enter||key && key->key() == Qt::Key_Return)
    {

    textEdit->insertPlainText("\n\t");
    return true;
    }
    }return false;
    }

    tabstopwidth is set to 4.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parenthesis Comparision with Enter key Event

    You will need to start looking into QTextDocument for advanced text manipulation.

    Cheers,
    _

  3. #3
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parenthesis Comparision with Enter key Event

    QTextDocument is the best way i think, but if you dont want to use it you can increase a counter when typed a { and decrease the count when } is typed
    I assume that } removes the indent (like source code editors do)

  4. The following user says thank you to StrikeByte for this useful post:

    parulkalra14 (23rd January 2014)

Similar Threads

  1. Qt widget enter/leave event
    By bunjee in forum Qt Programming
    Replies: 11
    Last Post: 28th April 2014, 03:09
  2. Enter key same event tab key
    By plopes21 in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2013, 14:46
  3. Replies: 1
    Last Post: 14th September 2008, 23:05
  4. QItemDelegate enter event
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 4th May 2008, 19:56
  5. Widget enter event
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 20th April 2008, 22:40

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.