Results 1 to 4 of 4

Thread: Align WindowTitle text to the Center in Windows 10

  1. #1
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Align WindowTitle text to the Center in Windows 10

    Hi

    I am using Qt 4.6.4 on Windows. I am using QMainWindow and using setWindowTitle to set the title bar text. But by default OS set it to the left Aligned. Is there function available to Align title bar text to the Center.

    Thanks
    Santosh

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Align WindowTitle text to the Center in Windows 10

    Window decorations are generally controlled by the window manager (i.e. Explorer in Windows) and are outside the control of application software. As far as I know, this cannot be changed through Qt. You may be able to find a Windows OS method that will do it, but I have no idea where to tell you to look.

  3. #3
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Align WindowTitle text to the Center in Windows 10

    Hi

    Is there any alternative or style sheet for QMainWindow or QDialog for Title Bar Text Alignment. I have one Alternative method for Align Text to the Center of MainWindow. Sample Code is below....

    void MainWindow::resizeEvent(QResizeEvent *event)
    {
    QString strTitle("My Application");
    QString strGap = QString(" ");

    QFont font("Arial",11);
    QFontMetrics fontM(font);
    int nWid = fontM.width(strTitle);
    int nWidSpace = fontM.width(strGap);

    int nLengthPixmap = 10;

    double STPoint = (double)((double)(this->width()/2-nLengthPixmap) - (double)nWid/2);
    double widthOfSpace = (double)nWidSpace;

    QString strG = QString(" ");
    double tmpWidth = 0;

    for(;(tmpWidth+widthOfSpace < STPoint)
    {
    strG += QString(" ");
    tmpWidth += widthOfSpace;
    }
    QString strFinal = strG + strTitle;// + strG;
    setWindowTitle(strFinal);
    }


    I have customize resizeEvent, it will set the title bar to the center. But problem is that, Due to Center Alignment text taskbar only show Application Icon followed by ....., I have attached the ScreenShot of My Application, Due to Center Alignment, Text shift also from TaskBar..

    Can you please give the solution that What is missing by me, After Center alignment of Window Title Text, Bottom Task Bar should also show Application's window title as in screenshot of other program..

    Thanks
    Santosh Kumar Singh
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Align WindowTitle text to the Center in Windows 10

    the solution that What is missing by me
    What you are "missing" is the understanding that your code cannot override what the Windows OS is doing with the alignment of the window title. Your code tries to fake it by left-padding the title with extra spaces. This isn't alignment, it is changing the title to make it longer. And the Windows OS is doing exactly what it is supposed to do - it is taking your title and making a task bar button out of it. If you give the window a title that is too long to fit into the task bar button, then you see an apparently blank label because you've left padded it with spaces.

Similar Threads

  1. Align text and icon of QToolButton on center
    By bibhukalyana in forum Qt Programming
    Replies: 7
    Last Post: 24th November 2014, 13:46
  2. Qwt, Align content to center
    By Asting in forum Qwt
    Replies: 3
    Last Post: 18th June 2014, 12:06
  3. Replies: 3
    Last Post: 20th February 2014, 16:14
  4. Replies: 2
    Last Post: 23rd February 2010, 08:52
  5. How to align list items to the center?
    By zgulser in forum Qt Tools
    Replies: 4
    Last Post: 9th February 2009, 10:52

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.