Results 1 to 3 of 3

Thread: Syntax issue with placing text inside a QProgressBar

  1. #1
    Join Date
    Jan 2017
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Syntax issue with placing text inside a QProgressBar

    I have a working Q Progress Bar with the percentage completion showing out to the right. I would like to add the text "Loading files" to the inside of the bar. In looking at the message boards for info, I found the following, which I think may do what I need (but have not tested):
    Found code:
    Qt Code:
    1. progressBar.setFormat("Loading...");
    2. progressBar.setAlignment(Qt::AlignCenter);
    To copy to clipboard, switch view to plain text mode 

    My code is this:
    Qt Code:
    1. self.ui.progressbar.setFormat('Loading files . . .')
    2. self.ui.progressbar.setAlignment(xxxxxxxxxxx)
    To copy to clipboard, switch view to plain text mode 

    I need help in translating the second line of the code I found into the format I need, ie., what do I put where the XXXXXXX are showing in my code? PyCharm, my IDE, gave me hints of what to put where the x's are like "Qt_Alignment=" but I don't know what else to put after the =
    Last edited by dennisvz; 8th December 2019 at 21:53.

  2. #2
    Join Date
    Jan 2017
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Syntax issue with placing text inside a QProgressBar

    UPDATE: I used:
    Qt Code:
    1. self.ui.progressbar.setStyleSheet('text-align: center')
    To copy to clipboard, switch view to plain text mode 

    and it works. But I would still like to know how to set the Alignment in the above question.

    Also, I have a related question:

    Throughout the loading process, I set the progress bar percentage with this code:
    Qt Code:
    1. progressBar.setValue(90)
    To copy to clipboard, switch view to plain text mode 

    with various percentages. Then what is the proper syntax/code to attach this percentage to the "loading files" text to get "Loading files 90%".
    the code should look something like:
    Qt Code:
    1. self.ui.progressbar.setFormat('Loading files . . .') + str(the percentage) ?????
    To copy to clipboard, switch view to plain text mode 
    thanks

  3. #3
    Join Date
    Jan 2017
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Syntax issue with placing text inside a QProgressBar

    RESOLVED: I finally found the answer. the following line does what I want.
    Qt Code:
    1. self.ui.progressbar.setFormat('Loading files . . .%p%')
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Issue placing a QOpenGLWidget in a QDockWidget
    By sandytf in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2015, 14:11
  2. Issue in placing the QGraphicsItems into QGraphicsLayout
    By aditya.kaole in forum Qt Programming
    Replies: 4
    Last Post: 9th September 2010, 07:33
  3. Building QT Staticly issue [The syntax of the command is incorrect.]
    By originof in forum Installation and Deployment
    Replies: 2
    Last Post: 13th August 2010, 13:21
  4. Replies: 4
    Last Post: 11th May 2010, 17:33
  5. compile issue, syntax i guess, but can't find it
    By incapacitant in forum Newbie
    Replies: 16
    Last Post: 29th March 2006, 20:32

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.