setWindowFilePath seems doesn't work
Hi !
I made a simple project with a simple MainWindow:
Code:
MainWindow
::MainWindow( QWidget *parent, Qt
::WFlags flags
){
ui.setupUi( this );
setWindowTitle( "My Program Caption[*] - " );
setWindowFilePath( "filename.ext" );
//setWindowModified( true );
}
and window has only "My Program Caption - " in it's title, but no "filename.ext".
It doesn't matter, if I call setWindowModified either with true or false, of if I don't call it at all...
The question is: how can I make a title of my window like this
Quote:
My Program Caption - filename.ext
?
Of course I can make it "by hands" every time I change filename, but I do not want to keep "clear" title ("My Program Caption - "). I want to call setWindowTitle one time in the constructor.
Thanks.
P.S. Windows 7, MSVC 2008, Qt 4.6.
Re: setWindowFilePath seems doesn't work
Use __FILE__ macro :
Code:
setWindowTitle
(QString("My Program Caption[*] - %1").
arg(__FILE__
));
Re: setWindowFilePath seems doesn't work
To quote the docs:
Quote:
If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.
Re: setWindowFilePath seems doesn't work
Quote:
Originally Posted by
Lesiok
Use __FILE__ macro
I do not want to include source file to window title. I want to include a filename, that my program works with. For example:
If notepad.exe edits somefile.txt, it's title is "Notepad - somefile.txt". I want the same, but to set an initial title ("Notepad - ") once in window's constructor, and to change only a filename each time user opens file to edit.
Quote:
Originally Posted by
wysota
To quote the docs:
If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.
I know this, but even I removed setWindowTitle and leave only setWindowFilePath, I had only application name in title, but not a filename, I gave with setWindowFilePath.
P.S. I understand, that I can do like this:
Code:
void MainWindow
::onFileOpen( const QString & filename
) { setWindowTitle( "My Caption - " + filename );
}
but where is a reason of setWindowFilePath function ???
Thanks.
Re: setWindowFilePath seems doesn't work
Quote:
Originally Posted by
borisbn
I know this, but even I removed setWindowTitle and leave only setWindowFilePath, I had only application name in title, but not a filename, I gave with setWindowFilePath.
Did you remove the call the Ui class generated by Designer/uic does as well?
Quote:
but where is a reason of setWindowFilePath function ???
The reason is the method is platform agnostic whereas your code is not.
Re: setWindowFilePath seems doesn't work
Quote:
Originally Posted by
wysota
Did you remove the call the Ui class generated by Designer/uic does as well?
Yes I did. I cleared a WindowTitle property in a designer, compiled and was convinced, that setWindowTitle was removed from ui_MainWindow.h file.
Finally I've done it. See, if setWindowFilePath is called from constructor title doesn't change because of (Qt sources)
Code:
void QWidgetPrivate
::setWindowTitle_helper(const QString &title
) {
if (q->testAttribute(Qt::WA_WState_Created))
setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q));
}
I moved call of setWindowFilePath to showEvent
Code:
void MainWindow
::showEvent( QShowEvent * event
) { static bool first = true;
if ( first ) {
first = false;
setWindowFilePath( m_fileName );
}
}
and it works fine, but... do you know a way to run some code once after Widget's class constructor, but without this ugly static bool ? And without calling singleShot from constructor ?
Re: setWindowFilePath seems doesn't work
single shot is ok, if you don't like it, you can use QMetaObject::invokeMethod().
Re: setWindowFilePath seems doesn't work
Ok, I trust you about single shot, but I think I'll use invokeMethod, because it can transmitt parameters to my function, such as a filename
Thank you once more