Results 1 to 2 of 2

Thread: hangup vertical scroll bar in qtextedit

  1. #1
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default hangup vertical scroll bar in qtextedit

    I've got textedit and i want display menu so i do:

    Qt Code:
    1. void MainTextEdit::mousePressEvent(QMouseEvent *event)
    2. {
    3. if (parent->isActiveWindow() == false) QTextEdit::mousePressEvent(event); // prevent bug
    4.  
    5. if (event->button() == Qt::RightButton)
    6. {
    7. if (this->textCursor().selectedText().isEmpty() == true) // if nothing selected
    8. {
    9. QTextCursor cursor = cursorForPosition(event->pos());
    10. cursor.select(QTextCursor::WordUnderCursor);
    11. if (!cursor.selectedText().isEmpty())
    12. {
    13. QString strText = cursor.selectedText();
    14. int iPos = cursor.position() - cursor.block().position(); // cursor.positionInBlock()
    15.  
    16. cursor.select(QTextCursor::BlockUnderCursor);
    17. QString strBlock = cursor.selectedText().trimmed();
    18. QStringList strlBlock = strBlock.split(" ");
    19.  
    20. QString strWord = strlBlock[1];
    21.  
    22. // channel
    23. if (strText.at(0) == '#')
    24. {
    25. ...
    26. QMenu *menu = new QMenu(strChannel);
    27. ...
    28. menu->popup(mapToGlobal(event->pos()));
    29. }
    30.  
    31. // nick
    32. if ((iPos > 11) && (iPos < 11+2+strWord.length()))
    33. {
    34. ...
    35. QMenu *menu = new QMenu(strNick);
    36. ...
    37. menu->popup(mapToGlobal(event->pos()));
    38. }
    39. }
    40. }
    41. }
    42. }
    43.  
    44. QTextEdit::mousePressEvent(event);
    45. }
    To copy to clipboard, switch view to plain text mode 

    this code is working good but sometimes vertical scroll bar stops, and moving it to bottom by mouse don't work - because after adding next line of text it back to "saved"? position ...

    maybe I forget to add something ?
    Last edited by mero; 16th February 2011 at 22:06.

  2. #2
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hangup vertical scroll bar in qtextedit

    I change to contextMenuEvent:

    Qt Code:
    1. void MainTextEdit::contextMenuEvent(QContextMenuEvent *event)
    2. {
    3. if (this->textCursor().selectedText().isEmpty() == true) // if nothing selected
    4. {
    5. QTextCursor cursor = cursorForPosition(event->pos());
    6. cursor.select(QTextCursor::WordUnderCursor);
    7. if (!cursor.selectedText().isEmpty())
    8. {
    9. QString strText = cursor.selectedText();
    10. int iPos = cursor.position() - cursor.block().position(); // cursor.positionInBlock()
    11.  
    12. cursor.select(QTextCursor::BlockUnderCursor);
    13. QString strBlock = cursor.selectedText().trimmed();
    14. QStringList strlBlock = strBlock.split(" ");
    15.  
    16. QString strWord = strlBlock[1];
    17.  
    18. // channel
    19. if (strText.at(0) == '#')
    20. {
    21. ...
    22. QMenu *menu = new QMenu(strChannel);
    23. ...
    24. menu->popup(event->globalPos());
    25. return;
    26. }
    27.  
    28. // nick
    29. if ((iPos > 11) && (iPos < 11+2+strWord.length()))
    30. {
    31. ...
    32. QMenu *menu = new QMenu(strNick);
    33. ...
    34. menu->popup(event->globalPos());
    35. return;
    36. }
    37. }
    38. }
    39.  
    40. QTextEdit::contextMenuEvent(event);
    41. }
    To copy to clipboard, switch view to plain text mode 

    but still sometimes vertical scroll bar stops ...

Similar Threads

  1. How to disable vertical scroll bar in QTableWidget
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2009, 11:07
  2. QListView with conditional vertical automatic scroll
    By jmesquita in forum Qt Programming
    Replies: 2
    Last Post: 1st August 2009, 03:09
  3. Vertical scroll bar, but resizable horizontal content
    By minimoog in forum Qt Programming
    Replies: 0
    Last Post: 14th January 2009, 20:51
  4. vertical scroll bar in Qt box.
    By rajveer in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2008, 07:41
  5. Vertical Scroll Bar - Style Sheet
    By vishesh in forum Qt Programming
    Replies: 2
    Last Post: 18th September 2007, 19:03

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.