Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Add styles to a QMessageBox
QtWS25 Last Chance

Add styles to a QMessageBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maria.v
    wrote on 29 Apr 2020, 17:41 last edited by
    #1

    I have this code to show a message box until a time-consuming task finish.

    QMessageBox msgBox(pqCoreUtilities::mainWidget());
    msgBox.setText("Initializing application");
    msgBox.setStandardButtons(0);
    msgBox.show();

    pqEventDispatcher::processEventsAndWait(100);

    It works but it looks ugly, example, the text doesn't seem to be centered.

    Is there a way to add styles?
    Or do something like this that gives me more control over how it looks?

    Screen Shot 2020-04-29 at 14.40.52.png

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 29 Apr 2020, 17:50 last edited by
      #2

      Hi
      It will react to stylesheets but i doubt you can center text.
      You could make your own based on QDialog so it could any way you like.
      Its not much work since you seem not to use any icons or buttons :)

      M 1 Reply Last reply 29 Apr 2020, 18:20
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 29 Apr 2020, 17:51 last edited by
        #3

        Hi,

        Since it looks it's happening at application startup, I would go with QSplashScreen.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply 29 Apr 2020, 18:18
        3
        • S SGaist
          29 Apr 2020, 17:51

          Hi,

          Since it looks it's happening at application startup, I would go with QSplashScreen.

          M Offline
          M Offline
          maria.v
          wrote on 29 Apr 2020, 18:18 last edited by
          #4

          @SGaist Unfortunately it doesn't happen at startup. it happens in 3 moment after triggering some button

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 29 Apr 2020, 18:20 last edited by
            #5

            Well, you can still use it there. Or a QProgressDialog with an infinite progress bar.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply 29 Apr 2020, 18:24
            1
            • M mrjj
              29 Apr 2020, 17:50

              Hi
              It will react to stylesheets but i doubt you can center text.
              You could make your own based on QDialog so it could any way you like.
              Its not much work since you seem not to use any icons or buttons :)

              M Offline
              M Offline
              maria.v
              wrote on 29 Apr 2020, 18:20 last edited by
              #6

              @mrjj I tried doing something like msgBox.setStylesheet("color: red;") but it didn't respond. Can you explain the other option a little more? Thanks

              M 1 Reply Last reply 29 Apr 2020, 18:30
              0
              • S SGaist
                29 Apr 2020, 18:20

                Well, you can still use it there. Or a QProgressDialog with an infinite progress bar.

                M Offline
                M Offline
                maria.v
                wrote on 29 Apr 2020, 18:24 last edited by
                #7

                @SGaist I tried first with the progress bar but I have no way to fill it, and leaving it empty also looks bad.
                Screen Shot 2020-04-29 at 15.22.47.png

                S 1 Reply Last reply 29 Apr 2020, 18:34
                0
                • M maria.v
                  29 Apr 2020, 18:20

                  @mrjj I tried doing something like msgBox.setStylesheet("color: red;") but it didn't respond. Can you explain the other option a little more? Thanks

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 29 Apr 2020, 18:30 last edited by
                  #8

                  @maria-v
                  Hi
                  Try
                  msgBox.setStyleSheet("background-color: rgb(255, 0, 0);");
                  and it should turn red.

                  Both QSplashScreen and QProgressDialog would also be good options as @SGaist mentions.

                  What i was talking about was a UI form QDialog made with the wizard.
                  alt text
                  alt text
                  and you get a new UI where you can add a label or other elements to make it look 100% as you wish.
                  alt text

                  alt text

                  1 Reply Last reply
                  0
                  • M maria.v
                    29 Apr 2020, 18:24

                    @SGaist I tried first with the progress bar but I have no way to fill it, and leaving it empty also looks bad.
                    Screen Shot 2020-04-29 at 15.22.47.png

                    S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 29 Apr 2020, 18:34 last edited by
                    #9

                    @maria-v said in Add styles to a QMessageBox:

                    @SGaist I tried first with the progress bar but I have no way to fill it, and leaving it empty also looks bad.
                    Screen Shot 2020-04-29 at 15.22.47.png

                    If you put the same value for min and Max, you'll have an infinite bar.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    M 1 Reply Last reply 29 Apr 2020, 19:13
                    0
                    • S SGaist
                      29 Apr 2020, 18:34

                      @maria-v said in Add styles to a QMessageBox:

                      @SGaist I tried first with the progress bar but I have no way to fill it, and leaving it empty also looks bad.
                      Screen Shot 2020-04-29 at 15.22.47.png

                      If you put the same value for min and Max, you'll have an infinite bar.

                      M Offline
                      M Offline
                      maria.v
                      wrote on 29 Apr 2020, 19:13 last edited by
                      #10

                      @SGaist said in Add styles to a QMessageBox:

                      infinite bar

                      What do you call "infinite bar"? I tried progress.setMinimum(0); progress.setMaximum(0); progress.setValue(0); and in Windows got
                      Captura (1).PNG

                      S 1 Reply Last reply 4 May 2020, 06:48
                      0
                      • B Offline
                        B Offline
                        Bonnie
                        wrote on 30 Apr 2020, 00:03 last edited by
                        #11

                        Cann't you just use a QLabel to do that?
                        I'm using a QLabel showing "Loading" when the ui is loading for seconds.
                        Seems you don't need any interactive functions.
                        And it is easy to be customized with stylesheet.

                        1 Reply Last reply
                        0
                        • M maria.v
                          29 Apr 2020, 19:13

                          @SGaist said in Add styles to a QMessageBox:

                          infinite bar

                          What do you call "infinite bar"? I tried progress.setMinimum(0); progress.setMaximum(0); progress.setValue(0); and in Windows got
                          Captura (1).PNG

                          S Offline
                          S Offline
                          SimonSchroeder
                          wrote on 4 May 2020, 06:48 last edited by
                          #12

                          @maria-v said in Add styles to a QMessageBox:

                          What do you call "infinite bar"? I tried progress.setMinimum(0); progress.setMaximum(0); progress.setValue(0); and in Windows got

                          I know this as "pulsing progress bar". However, you need to process incoming events occasionally in order to have that pulsating bar. The easiest (though not the preferred way) is to put QApplication::processEvents() in several places which will allow the progress dialog to update.

                          1 Reply Last reply
                          1

                          6/12

                          29 Apr 2020, 18:20

                          • Login

                          • Login or register to search.
                          6 out of 12
                          • First post
                            6/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved