2

I have a QLineEdit to which I set the echoMode to QLineEdit::Password like this:

myLineEdit->setEchoMode(QLineEdit::Password);

The bullets are shown, but they are too small for the purpose of my application:

enter image description here

I need to make them bigger like this:

enter image description here

I have tried to increase the font size using a stylesheet like that:

myLineEdit->setStyleSheet("QLineEdit { font-size: 20px; }");

This indeed makes the bullets bigger, but the text gets bigger as well.

How to increase the size of bullet points preserving the size of the text?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
trangan
  • 341
  • 8
  • 22

1 Answers1

3

You can set a unicode character that shows a larger circle through lineedit-password-character:

#include <QApplication>
#include <QFormLayout>
#include <QLineEdit>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget w;
    auto lay = new QFormLayout(&w);
    QLineEdit *normal_le = new QLineEdit;
    normal_le->setEchoMode(QLineEdit::Password);
    normal_le->setText("Pass");
    lay->addRow("Normal: ", normal_le);
    for(int i: {9210, 9679, 9899, 11044}){
        QLineEdit *le = new QLineEdit;
        le->setEchoMode(QLineEdit::Password);
        le->setText("Pass");
        le->setStyleSheet(QString("QLineEdit[echoMode=\"2\"]{lineedit-password-character: %1}").arg(i));
        lay->addRow(QString::number(i), le);
    }
    w.show();

    return a.exec();
}

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I have one more question. This solution works well until I applied it for MacOS. I used the value 11044, but the circle does not appear in MacOS, instead only strange rectangulars appear. Could you pls tell me which reason could be for this? – trangan Oct 08 '18 at 15:24
  • @htmlamateur The problem is the font you are using, if the font does not support unicode then you will generate that problem, solution: use another font. – eyllanesc Oct 08 '18 at 17:48
  • I use the same font for windows and Mac, in windows that works but in Mac that does not :( – trangan Oct 09 '18 at 07:17
  • @htmlamateur What font am I using? – eyllanesc Oct 09 '18 at 07:43
  • Sorry I looked again in Mac I use another font (HelveticaNeue), I am checking whether this font supports unicode – trangan Oct 09 '18 at 07:56
  • OK, i have checked. It seems HelveticaNeue does not support Unicode. thank you! Do we have another solution for the problem if the font can not be changed ? – trangan Oct 09 '18 at 08:49
  • @htmlamateur No, there is no other solution, use another font :-) – eyllanesc Oct 09 '18 at 08:50