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. Format content of messageBox

Format content of messageBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 947 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.
  • C Offline
    C Offline
    ChiaoHuang
    wrote on 20 Mar 2022, 15:44 last edited by
    #1

    Hi ,
    I'd like to show some message.
    I will set the message to QString class and then show messagebox

    Unlucky, it is not what I want in the messagebox.

    This is my example code

        char *info[] = {"Apple", "Banana", "Strawberrie", "Grape"};
        char tmp[1024];
        QString s;
    
        for(int i=0; i<30; i=i+10)
        {
            for(int j=0; j<4; j++)
            {
                sprintf(tmp, "[%2d] %15s = %2d\n", i, info[j], j);
                s.append(tmp);
            }
        }
    
        qDebug() << s;
        QMessageBox::information(NULL,  "Fruits",  s, QMessageBox::Yes, QMessageBox::Yes);
    

    The result
    alt text

    I want the content of messagebox same as the debug message.
    How to do?

    Thanks a lot

    M 1 Reply Last reply 20 Mar 2022, 15:49
    0
    • C ChiaoHuang
      20 Mar 2022, 15:44

      Hi ,
      I'd like to show some message.
      I will set the message to QString class and then show messagebox

      Unlucky, it is not what I want in the messagebox.

      This is my example code

          char *info[] = {"Apple", "Banana", "Strawberrie", "Grape"};
          char tmp[1024];
          QString s;
      
          for(int i=0; i<30; i=i+10)
          {
              for(int j=0; j<4; j++)
              {
                  sprintf(tmp, "[%2d] %15s = %2d\n", i, info[j], j);
                  s.append(tmp);
              }
          }
      
          qDebug() << s;
          QMessageBox::information(NULL,  "Fruits",  s, QMessageBox::Yes, QMessageBox::Yes);
      

      The result
      alt text

      I want the content of messagebox same as the debug message.
      How to do?

      Thanks a lot

      M Offline
      M Offline
      mpergand
      wrote on 20 Mar 2022, 15:49 last edited by
      #2

      @ChiaoHuang
      Use a fixed width /mono spaced font.

      1 Reply Last reply
      3
      • C Offline
        C Offline
        ChiaoHuang
        wrote on 26 Mar 2022, 12:49 last edited by
        #3

        @mpergand
        I am sorry for the late reply
        I am trying it, but it doesn't work.

            msgFont.setStyleHint(QFont::Monospace);
            msg.setFont(msgFont);
            msg.setFixedWidth(1200);
            msg.setText(s);
            msg.setStandardButtons(QMessageBox::Yes);
            msg.exec();
        

        alt text

        Thanks

        J M C 3 Replies Last reply 26 Mar 2022, 13:08
        0
        • C ChiaoHuang
          26 Mar 2022, 12:49

          @mpergand
          I am sorry for the late reply
          I am trying it, but it doesn't work.

              msgFont.setStyleHint(QFont::Monospace);
              msg.setFont(msgFont);
              msg.setFixedWidth(1200);
              msg.setText(s);
              msg.setStandardButtons(QMessageBox::Yes);
              msg.exec();
          

          alt text

          Thanks

          J Offline
          J Offline
          JonB
          wrote on 26 Mar 2022, 13:08 last edited by JonB
          #4

          @ChiaoHuang
          What type/declaration is this msg variable? It does not seem to obey msg.setFixedWidth(1200); either? Originally you used QMessageBox::information() which is static, so what is going on now in your code?

          I only know that https://stackoverflow.com/a/22587461/489865 from 2014 claims to work, you could test that (with a suitable combobox populated, or hard-coded value). If it really does not work you could test out HTML font markup, or even QSS/CSS.

          1 Reply Last reply
          0
          • C ChiaoHuang
            26 Mar 2022, 12:49

            @mpergand
            I am sorry for the late reply
            I am trying it, but it doesn't work.

                msgFont.setStyleHint(QFont::Monospace);
                msg.setFont(msgFont);
                msg.setFixedWidth(1200);
                msg.setText(s);
                msg.setStandardButtons(QMessageBox::Yes);
                msg.exec();
            

            alt text

            Thanks

            M Offline
            M Offline
            mpergand
            wrote on 26 Mar 2022, 14:42 last edited by
            #5

            @ChiaoHuang
            try:

            msg.setFont(QFont("courier")); // or monaco or any fixed font name available on your system
            

            or get the default fixed font with:

            QFont font=QFontDatabase::systemFont(QFontDatabase::FixedFont);
            
            C 1 Reply Last reply 27 Mar 2022, 15:51
            1
            • C ChiaoHuang
              26 Mar 2022, 12:49

              @mpergand
              I am sorry for the late reply
              I am trying it, but it doesn't work.

                  msgFont.setStyleHint(QFont::Monospace);
                  msg.setFont(msgFont);
                  msg.setFixedWidth(1200);
                  msg.setText(s);
                  msg.setStandardButtons(QMessageBox::Yes);
                  msg.exec();
              

              alt text

              Thanks

              C Offline
              C Offline
              ChiaoHuang
              wrote on 27 Mar 2022, 15:40 last edited by
              #6

              @ChiaoHuang
              I created a "QMessageBox msg" for using Font.
              Yes, I don't know why the msg.setFixedWidth(1200) is not working.

              Thank you. I think the HTML font markup should work.

              1 Reply Last reply
              0
              • M mpergand
                26 Mar 2022, 14:42

                @ChiaoHuang
                try:

                msg.setFont(QFont("courier")); // or monaco or any fixed font name available on your system
                

                or get the default fixed font with:

                QFont font=QFontDatabase::systemFont(QFontDatabase::FixedFont);
                
                C Offline
                C Offline
                ChiaoHuang
                wrote on 27 Mar 2022, 15:51 last edited by
                #7

                @mpergand said in Format content of messageBox:

                msg.setFont(QFont("courier"));

                Thank you so much
                It is working now after I used msg.setFont(QFont("consolas"));

                1 Reply Last reply
                0

                2/7

                20 Mar 2022, 15:49

                topic:navigator.unread, 5
                • Login

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