qtalignmentqstatusbar

qt status bar center align?


How can I center align the text in QStatusBar? By default it is always left aligned.

I know I can add a QLabel and set alignment, but I want to use plain text, and .showMessage(QString, int) method, so I can add the timeout value.


Solution

  • A QStatusBar has three functions of note here:

    addPermanentWidget - Places a widget right aligned

    addWidget - Places a widget left aligned which can be obscured by status messages

    showMessage - Displays a status message

    These are well established standards for status bars. While you could hack away to get what you're looking for, I'd suggest you reconsider your needs. Perhaps your QLabel should be placed with addPermanentWidget instead?

    Take a look at the docs for more info: http://doc.qt.io/qt-5/qstatusbar.html