Qt/C++から簡単なメモ帳を作成しました。私は、あなたが「エディタ」ウィジェットとしてQTextEditを使用している推測しているQtシンプルなメモ帳、QmainWindowのステータスバーにある印刷行番号
0
A
答えて
2
ますテキスト領域のcursorPositionChanged()
信号をQMainWindow
のカスタムスロットに接続できます。
// the connection
connect(ui->plainTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(showCursorPos()));
// your custom slot
void MainWindow::showCursorPos()
{
int line = ui->plainTextEdit->textCursor().blockNumber()+1;
int pos = ui->plainTextEdit->textCursor().columnNumber()+1;
ui->statusBar->showMessage(QString("Ln %1, Col %2").arg(line).arg(pos));
}
+0
ありがとう、この回答は私のために働いた –
0
のMicrosoft Windowsのメモ帳のように、私はテキスト領域のどこかをクリックしたときにQMainWindow
のステータスバーに行番号を印刷したいです。
あなたQTextEditでカーソルです、あなたは
row = myTextEdit->textCursor()->blockNumber();
と列に
column = myTextEdit->textCursor()->positionInBlock();
を使うべき場所を取得するにそれからちょうどこれらに関する情報を使用して、ステータスバーのテキストを編集
何を試しましたか?テキスト編集の現在のカーソル位置と、ステータスバーにテキストを設定する方法が必要です。 ;) – xander
はこのQPointですglobalCursorPos = QCursor :: pos();現在のカーソル位置に有効で、どのように印刷することができますか –