Results 1 to 8 of 8

Thread: setWindowFilePath seems doesn't work

  1. #1
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default setWindowFilePath seems doesn't work

    Hi !
    I made a simple project with a simple MainWindow:

    Qt Code:
    1. MainWindow::MainWindow( QWidget *parent, Qt::WFlags flags )
    2. : QMainWindow( parent, flags )
    3. {
    4. ui.setupUi( this );
    5.  
    6. setWindowTitle( "My Program Caption[*] - " );
    7. setWindowFilePath( "filename.ext" );
    8. //setWindowModified( true );
    9. }
    To copy to clipboard, switch view to plain text mode 
    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
    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.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setWindowFilePath seems doesn't work

    Use __FILE__ macro :
    Qt Code:
    1. setWindowTitle(QString("My Program Caption[*] - %1").arg(__FILE__));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setWindowFilePath seems doesn't work

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setWindowFilePath seems doesn't work

    Quote Originally Posted by Lesiok View Post
    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 View Post
    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:
    Qt Code:
    1. void MainWindow::onFileOpen( const QString & filename ) {
    2. setWindowTitle( "My Caption - " + filename );
    3. }
    To copy to clipboard, switch view to plain text mode 
    but where is a reason of setWindowFilePath function ???
    Thanks.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setWindowFilePath seems doesn't work

    Quote Originally Posted by borisbn View Post
    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?

    but where is a reason of setWindowFilePath function ???
    The reason is the method is platform agnostic whereas your code is not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setWindowFilePath seems doesn't work

    Quote Originally Posted by wysota View Post
    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)
    Qt Code:
    1. void QWidgetPrivate::setWindowTitle_helper(const QString &title)
    2. {
    3. Q_Q(QWidget);
    4. if (q->testAttribute(Qt::WA_WState_Created))
    5. setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q));
    6. }
    To copy to clipboard, switch view to plain text mode 
    I moved call of setWindowFilePath to showEvent
    Qt Code:
    1. void MainWindow::showEvent( QShowEvent * event ) {
    2. QWidget::showEvent( event );
    3. static bool first = true;
    4. if ( first ) {
    5. first = false;
    6. setWindowFilePath( m_fileName );
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    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 ?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setWindowFilePath seems doesn't work

    single shot is ok, if you don't like it, you can use QMetaObject::invokeMethod().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

Similar Threads

  1. macdeployqt doesn't work at all.
    By pherthyl in forum Installation and Deployment
    Replies: 1
    Last Post: 10th July 2009, 00:42
  2. Q_PROPERTY: the example doesn't work!
    By YaK in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2009, 11:28
  3. Privoxy doesn't work with qt 4.5.1
    By doep in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2009, 10:55
  4. activateWindow() doesn't work
    By roxton in forum Qt Programming
    Replies: 8
    Last Post: 26th December 2008, 09:49
  5. Connection doesn't work
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2007, 12:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.