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. [Solved] Set Font of QTextEdit and QListWidget
Forum Updated to NodeBB v4.3 + New Features

[Solved] Set Font of QTextEdit and QListWidget

Scheduled Pinned Locked Moved General and Desktop
21 Posts 4 Posters 69.9k Views 1 Watching
  • 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.
  • EddyE Offline
    EddyE Offline
    Eddy
    wrote on last edited by
    #10

    So using courier to get fixed width is not the best approach to get what you want.

    Could you give us a screenshot of your dialog? There might be other Qt ways to get what you want.

    Qt Certified Specialist
    www.edalsolutions.be

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kbt90
      wrote on last edited by
      #11

      Here is the code for the dialog. It has a text box and underneath is a button bar.

      @setWindowTitle ("Title");
      QVBoxLayout *mainLayout = new QVBoxLayout;

      textEdit = new QTextEdit (this);
      QFont font = QFont ("Courier");
      font.setStyleHint (QFont::Monospace);
      font.setPointSize (8);
      font.setFixedPitch (true);
      textEdit->setFont (font);

      mainLayout->addWidget (textEdit);
      setAutoFillBackground(true);

      QHBoxLayout *bar = new QHBoxLayout;
      btnBack = new QPushButton ("Back", this);
      btnBack->setMinimumSize (QSize (80, 40));
      bar->addWidget (btnBack);
      btnSave = new QPushButton ("Save", this);
      btnSave->setMinimumSize (QSize (80, 40));
      bar->addWidget (btnSave);
      btnPrint = new QPushButton ("Print", this);
      btnPrint->setMinimumSize (QSize (80, 40));
      bar->addWidget (btnPrint);
      btnErase = new QPushButton ("Erase", this);
      btnErase->setMinimumSize (QSize (80, 40));
      bar->addWidget (btnErase);
      bar->addStretch ();

      mainLayout->addLayout (bar);
      mainLayout->setContentsMargins (6, 6, 6, 6);
      setLayout (mainLayout);
      @

      Thanks for your help,
      Katelyn

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #12

        As I see this, you have a QTextEdit on top and beneath it a line of four buttons.

        I don't see the QListWidget.

        What do you want to line up?

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kbt90
          wrote on last edited by
          #13

          Oops - sorry about that. Here is an updated version:

          @setWindowTitle ("Title");
          QVBoxLayout *mainLayout = new QVBoxLayout;

          lwListWidget = new QListWidget (this);
          QFont font = QFont ("Courier");
          font.setStyleHint (QFont::Monospace);
          font.setPointSize (8);
          font.setFixedPitch (true);
          lwListWidget->setFont (font);

          mainLayout->addWidget (lwListWidget);
          setAutoFillBackground(true);

          QHBoxLayout *bar = new QHBoxLayout;
          btnBack = new QPushButton ("Back", this);
          btnBack->setMinimumSize (QSize (80, 40));
          bar->addWidget (btnBack);
          btnSave = new QPushButton ("Save", this);
          btnSave->setMinimumSize (QSize (80, 40));
          bar->addWidget (btnSave);
          btnPrint = new QPushButton ("Print", this);
          btnPrint->setMinimumSize (QSize (80, 40));
          bar->addWidget (btnPrint);
          btnErase = new QPushButton ("Erase", this);
          btnErase->setMinimumSize (QSize (80, 40));
          bar->addWidget (btnErase);
          bar->addStretch ();

          mainLayout->addLayout (bar);
          mainLayout->setContentsMargins (6, 6, 6, 6);
          setLayout (mainLayout);@

          Then I add items with the following code:
          @QListWidgetItem * tmpItem = new QListWidgetItem(temp, lwListWidget); // where temp is a QString
          QFont font = QFont ("Courier");
          font.setStyleHint (QFont::Monospace);
          font.setPointSize (8);
          font.setFixedPitch (true);
          tmpItem->setFont (font);@

          I cannot add the items directly in Qt Designer or in the constructor because I won't know what they are at that time.

          Thanks,
          Katelyn

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #14

            Ok, you have a QListWidget on top and beneath it a line of four buttons.

            What do you want to line up?

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kbt90
              wrote on last edited by
              #15

              Within the QListWidget I have a list of items. These items display a name, date and a status.

              For example:
              JobA June 26, 2011 Completed
              JobB July 4, 2011 In Progress

              Names, dates and statuses are different lengths, but I would like each column to match up. I am trying a QTableView and only allowing complete rows to be selected. Does this seem like an acceptable solution?

              1 Reply Last reply
              0
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #16

                Of course, QTableview will make the columns adapt to the contents.
                You can make the grid not visible if you want.
                QTableView can be set to select/highlight an entire row.

                Qt Certified Specialist
                www.edalsolutions.be

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kbt90
                  wrote on last edited by
                  #17

                  Super - thanks so much for your help.

                  1 Reply Last reply
                  0
                  • EddyE Offline
                    EddyE Offline
                    Eddy
                    wrote on last edited by
                    #18

                    You're welcome.

                    If you have more specific questions, feel free to ask.

                    Qt Certified Specialist
                    www.edalsolutions.be

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sasireka
                      wrote on last edited by
                      #19

                      i tried like this. it is working for english fonts. but it is not working for tamil fonts.
                      @ui->label1->setStyleSheet ("font: 40pt "Lohit Tamil";");
                      ui->label1->setText("சென்னை");
                      //ui->label1->setText("tamil");
                      ui->label1->show();@

                      [quote author="Eddy" date="1311141291"]You can find the explanation for that behaviour in the "QWidget docs :":http://doc.qt.nokia.com/4.7/qwidget.html#font-prop

                      You can solve this by giving your whole dialog the font you want in it's constructor :
                      @setFont (QFont ("Courier", 9)); @
                      But I don't know if that's ok with your initial design.

                      The easiest way to solve this is to use stylesheets which take precedence over setFont.
                      @ui->textEdit->setStyleSheet("font: 9pt "Courier";");@
                      (You can experiment with this using Qt Designer : RMB on a widget > Change Stylesheet.)

                      But using stylesheets per widget doesn't use it's real force. You can set this for the whole of your application to get a look and feel which is the same everywhere.
                      [/quote]

                      .................................
                      Thanks & Regards

                      Sasi

                      .................................
                      Go Green

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kumararajas
                        wrote on last edited by
                        #20

                        Hi Sasireka,

                        Do you have tamil font installed in your computer?

                        --Kumar

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          kumararajas
                          wrote on last edited by
                          #21

                          "This question has been solved here: ":http://qt-project.org/forums/viewthread/47761/

                          --Kumar

                          1 Reply Last reply
                          0

                          • Login

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