QTextDocument *document = ui->description->document()
ui->description->setHtml(ui->description->document()->toPlainText())
int number=0
bool found = false
QTextCursor highlightCursor(document)
QTextCharFormat plainFormat(highlightCursor.charFormat())
QTextCharFormat colorFormat = plainFormat
colorFormat.setForeground(Qt::red)
if(ui->description->toPlainText()==""){
QMessageBox::information(this, tr("description first"),
"Sorry, please display the description first!")
}
else{
ui->result->setPlainText("")
QString resultstring="搜索结果:"
QString laststring
/*while循环体是本代码的关键-——开始——*/
while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
if(ui->daxiaocheckBox->isChecked()==true){
highlightCursor = document->find(searchString, highlightCursor,QTextDocument::FindCaseSensitively)
}//这个是实现大小写区分效果的代码,你可能不需要
else
highlightCursor = document->find(searchString, highlightCursor)
if (!highlightCursor.isNull()) {
number++
found = true
highlightCursor.movePosition(QTextCursor::Right,QTextCursor::KeepAnchor,0)
highlightCursor.mergeCharFormat(colorFormat)
laststring=QString::number(highlightCursor.position(),10)
if(ui->onlyTwo->isChecked()==true){
if(number<巧链=1)
resultstring+="n occurrence"+QString::number(number,10)+":—— position:"+QString::number(highlightCursor.position(),10)
}//这个孝慧孙是实现大小写区分效果的代码,你可能不需要
else
resultstring+="n occurrence"+QString::number(number,10)+":—— position:"+QString::number(highlightCursor.position(),10)
}
}
/*关键代码结束*/
if(number>1&&ui->onlyTwo->isChecked()==true)
resultstring+="n occurrence"+QString::number(number,10)+":—— position:"+laststring
ui->result->setPlainText(resultstring)
if (found == false) {
QMessageBox::information(this, tr("Word Not Found"),
"Sorry, the word cannot be found.")
}
else 碧启{
QMessageBox::information(this, tr("Word was Found"),
"the word '"+searchString+"' was found for "+QString::number(number,10)+((number>1)? " times":" time"))
}
}
搜狗浏览器烂脊枣不是用的“编辑”这个词来描野友叙你说的那些IE浏览器里面的功能,你在浏览器上方饥拆点击右键
选择“查找栏”就出现了,这样就可以查找文字了。搜狗浏览器快捷键: 查找CTRL+F 复制CTRL+C 粘贴CTRL+V 剪切CTRL+V
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)