
Originally Posted by
kja
Hi,
Is it possible to treat each line of a qtextedit individually and attach them to a slot? I know I can get the text from each line and treat it separately but what I want to do is be able to push a shortcut key (like control+r) when the curser is on a line and have that call a function.
Specifically what I want is this: have a qtextedit with a list of file names that I plot. When the cursor is on one of the lines and i press control+t I want that file to be plotted on the right Y-axis.
Right now I am getting the text and plotting it like this
QString textEntered
= this
->textedit
->toPlainText
();
line = line.trimmed();
Filepath = qstrudup(line.toLatin1() );
myPlot->plotFile(Filename)
}
}
QString textEntered = this->textedit->toPlainText();
QStringList lines = textEntered.split( "\n", QString::SkipEmptyParts );
foreach( QString line, lines ) {
line = line.trimmed();
Filepath = qstrudup(line.toLatin1() );
myPlot->plotFile(Filename)
}
}
To copy to clipboard, switch view to plain text mode
I'm not sure if I'd use this same kind of thing or not.
And I know, I know, it would be much easier to use individual qlineedits, but my boss wants the textedit.
Thanks!
Hi,
I don't answer your question but I give you another idea that is very easier to implementing,
Use a QTableWidget with one column and enable stretch last section for horizontal header, every row of table contains one of your document block/line ( file name ).
Now, you're ready to go, just use "itemEntered( QTableWidgetItem * item )" signal, like this,
//table initialization
table->setColumnCount(1);
table->setRowCount( Number of lines );
//horHeader->hide();
horHeader->setStretchLastSection(true);
////////////////////////////////////////
{
myPlot->plotFile(Filename)
}
//table initialization
QTableWidget *table = new QTableWidget(this);
table->setColumnCount(1);
table->setRowCount( Number of lines );
QHeaderView *horHeader = table->horizontalHeader();
//horHeader->hide();
horHeader->setStretchLastSection(true);
connect(table, SIGNAL(itemEntered( QTableWidgetItem * item )), this, mouseOverLine( QTableWidgetItem * item ));
////////////////////////////////////////
void MainWindow::mouseOverLine( QTableWidgetItem * item )
{
QString Filename= item->text();
myPlot->plotFile(Filename)
}
To copy to clipboard, switch view to plain text mode
Bookmarks