Reputation: 2605
Right now I am displaying something like /home/binary/ in QText browser. Now I want the open the folder by clicking on this text. How to do that ? Thanks in advance
Here is my sample code. I am display the result s
bool MainWindow::displayResult(multimap<string,
string> &resultMap, string &filePath) { multimap::iterator iter; bool fileStatus = false; int noOfLocFound = 0, forAppending = 0; QString no;
noOfLocFound = resultMap.size(); if ( noOfLocFound != 0 ) ui->textBrowser->append( "<i>File found at <b>" + no.setNum (
noOfLocFound ) + " locations");
for ( forAppending = 0,iter = resultMap.begin(); iter !=
resultMap.end(); iter++, forAppending++ ) { string file = iter->first; string dir = iter->second;
if ( forAppending == 0) filePath.append(dir); else filePath.append(","+dir); QString qdir = QString::fromStdString(dir); cout << "Display"; ui->textBrowser->append( qdir ); fileStatus = true; } if ( fileStatus == false ) { ui->textBrowser->append("File not
found"); return false; }
return true; }
Upvotes: 0
Views: 230
Reputation: 8901
By "open the folder", do you mean, open a file dialog for the user to select something inside of the given directory?
If so, you would probably want to connect your QTextBrowser's clicked signal to a slot that looked something like:
// connect events, in MyWindow constructor, or whereever...
connect(textbrowser, SIGNAL(mousePressEvent(QMouseEvent*)), this, SLOT(openFileDialog(QMouseEvent*)));
void MyWindow::openFileDialog(QMouseEvent* event) {
Q_UNUSED(event);
QStringList files = QFileDialog::getOpenFileNames(this, "Select a file...",
textbrowser.plainText());
// do something with the files here...
}
Upvotes: 0