Results 1 to 2 of 2

Thread: Move QCompleter on QRect x,y

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Move QCompleter on QRect x,y

    i find QsciScintilla a super libs but code AutoCompletion not run ok... it display a not clickable widged.... ( only keyboard can secect!)

    i have implement the QT4 QCompleter combobox and its run Super..

    only its display on not correct place ....
    my problem how i can find the cursor QRect on QsciScintilla?



    i bring QsciScintilla getWord(int position) to public and i can bring word to QCompleter class...


    Qt Code:
    1. /* completer from qt4 make it */
    2. void QViScintilla::CursorAtIndex(int line ,int cool )
    3. {
    4. /* start from connect(this, SIGNAL(cursorPositionChanged(int,int)),this, SLOT(CursorAtIndex(int,int))); */
    5. setAutoCompletionFillupsEnabled(false); /* ensure not start scite autoxx */
    6. int newPos = SendScintilla(SCI_GETCURRENTPOS);
    7. CURRENTWORD = getWord(newPos); /* bring getWord(int position) to public !!!!! */
    8. qDebug() << "### word " << CURRENTWORD; /* word piece on cursor */
    9. }
    10.  
    11. /* now i display it so ... its not correct cursor position ..... display qt4 QCompleter */
    12. QPoint pointers(QCursor::pos());
    13. QRect cr = QRect ( posX, posY ,20,20);
    14. cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
    15. c->complete(cr); // popup it up!
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Move QCompleter on QRect x,y

    I resolve the problem to paint on QsciScintilla a QT4 QCompleter read this code line...

    to become the same X,Y as

    QTextEdit::cursorRect()
    Qt Code:
    1. /* constructor */
    2. connect(this, SIGNAL(cursorPositionChanged(int,int)),this, SLOT(CursorAtIndex(int,int)));
    3. baseram = QApplication::clipboard(); /* capture word on clipboard & keyPressEvent */
    4. completerbase = new QCompleter();
    5. completerbase->setModel(modelFromFile(":/img/_htmlwordslist.txt"));
    6. completerbase->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
    7. completerbase->setCaseSensitivity(Qt::CaseInsensitive);
    8. setCompleter(completerbase);
    9.  
    10.  
    11. /* constructor */
    12.  
    13. /* completer from qt4 make it */
    14. void QViScintilla::CursorAtIndex(int line ,int cool )
    15. {
    16. /* start from connect(this, SIGNAL(cursorPositionChanged(int,int)),this, SLOT(CursorAtIndex(int,int))); */
    17. setAutoCompletionFillupsEnabled(false);
    18. int newPos = SendScintilla(SCI_GETCURRENTPOS);
    19. posX = SendScintilla(SCI_POINTXFROMPOSITION, 0, newPos);
    20. posY = SendScintilla(SCI_POINTYFROMPOSITION, 0, newPos);
    21. CURRENTWORD = TextUnderCursor(newPos); /* bring getWord(int position) to public !!!!! */
    22. ///////////qDebug() << "### word " << CURRENTWORD; /* word piece on cursor */
    23. }
    24.  
    25. void QViScintilla::setCompleter(QCompleter *completer)
    26. {
    27. if (c)
    28. QObject::disconnect(c, 0, this, 0);
    29. c = completer;
    30. if (!c) {
    31. return;
    32. }
    33. c->setWidget(this);
    34. c->setCompletionMode(QCompleter::PopupCompletion);
    35. c->setCaseSensitivity(Qt::CaseSensitive);
    36. connect(c, SIGNAL(activated(const QString&)), this, SLOT(insertCompletion(const QString&)));
    37. }
    38.  
    39.  
    40.  
    41. void QViScintilla::keyPressEvent(QKeyEvent *e)
    42. {
    43.  
    44. if (c && c->popup()->isVisible()) {
    45. // The following keys are forwarded by the completer to the widget
    46. switch (e->key()) {
    47. case Qt::Key_Enter:
    48. case Qt::Key_Return:
    49. case Qt::Key_Escape:
    50. case Qt::Key_Backtab:
    51. e->ignore();
    52. return; // let the completer do default behavior
    53. default:
    54. break;
    55. }
    56. }
    57.  
    58. bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
    59. if (!c || !isShortcut) {
    60. QsciScintillaBase::keyPressEvent(e);
    61. }
    62.  
    63. const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
    64. if (!c || (ctrlOrShift && CURRENTWORD.isEmpty())) {
    65. return;
    66. }
    67. static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
    68. bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
    69.  
    70. if (!isShortcut && (hasModifier || CURRENTWORD.isEmpty()|| completionPrefix.length() < 2 || eow.contains(CURRENTWORD.right(1)))) {
    71. c->popup()->hide();
    72. return;
    73. }
    74.  
    75. if (CURRENTWORD != c->completionPrefix()) {
    76. c->setCompletionPrefix(CURRENTWORD);
    77. c->popup()->setCurrentIndex(c->completionModel()->index(0, 0));
    78. }
    79.  
    80. QRect cr = QRect (posX, posY ,20,20);
    81. cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
    82. c->complete(cr); // popup it up!
    83. }
    84.  
    85.  
    86.  
    87. QAbstractItemModel *QViScintilla::modelFromFile(const QString& fileName)
    88. {
    89.  
    90. QFile file(fileName);
    91. if (!file.open(QFile::ReadOnly))
    92. return new QStringListModel(completer);
    93.  
    94. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    95. QStringList words;
    96.  
    97. while (!file.atEnd()) {
    98. QByteArray line = file.readLine();
    99. if (!line.isEmpty())
    100. words << line.trimmed();
    101. }
    102.  
    103. QApplication::restoreOverrideCursor();
    104. return new QStringListModel(words, completer);
    105. }
    106.  
    107.  
    108. /*
    109. on class QSCINTILLA_EXPORT QsciScintilla : public QsciScintillaBase
    110. append on public ! && rebuild lib.. static
    111. inline QString TextUnderCursor(int &pos) {
    112.   return getWord(pos);
    113.  }
    114.  
    115. */
    To copy to clipboard, switch view to plain text mode 


    [HTML]
    ### on Qt4.pro set .. +mac intel + ppc to have only one static lib
    !win32:VERSION = 3.0.0

    TEMPLATE = lib
    TARGET = qscintilla2
    CONFIG += qt warn_off release staticlib thread
    INCLUDEPATH = . ../include ../src
    DEFINES = QT SCI_LEXER

    # Handle both Qt v4 and v3.

    DESTDIR = ../../all_os_libs


    macx {
    QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk
    CONFIG+=x86 ppc
    }

    [/HTML]

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.