Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How do you properly increase QLineEdit increase icon size/

    General and Desktop
    qlineedit icon size pixelated
    3
    4
    821
    Loading More Posts
    • 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.
    • A
      arjun98 last edited by

      I have been trying to add an icon to a QLineEdit object to the effect of:
      Screen Shot 2021-04-27 at 10.39.46 PM.png
      In order to this I implemented the following code:

        ui->searchbar->setClearButtonEnabled(true);
        ui->searchbar->QLineEdit::addAction(QIcon(":/img/icons/icon_search.png"), QLineEdit::LeadingPosition);
      

      This is the result I got:
      Screen Shot 2021-04-27 at 10.38.20 PM.png

      In order to try and enlarge it I tried:

       QPixmap in(":/img/icons/icon_search.png");
       QPixmap out(in.size()*0.5);
       QRect r= in.rect();
      
       r.moveCenter(out.rect().center());
       out.fill(Qt::transparent);
      
       QPainter painter(&out);
       painter.drawPixmap(r , in);
       painter.end();
      
       ui->searchbar->setClearButtonEnabled(true);
       ui->searchbar->QLineEdit::addAction(QIcon(out), QLineEdit::LeadingPosition);
      

      However, this produced the following:
      Screen Shot 2021-04-27 at 10.46.03 PM.png
      If you notice the icon is partially cut.
      The second thing I would like to fix is that the icon is pixelated, however, it is smaller than the size of the .png file. (It is an icon from material.io)
      Thank you for your help,
      arjun

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        What is the original size ?
        What not use the scaled function of QPixmap to make it bigger ?

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

        A 1 Reply Last reply Reply Quote 0
        • A
          arjun98 @SGaist last edited by

          @SGaist The original size is 48 by 48, when I open the .png file with an image reader outside of qt it is larger and clear, it also maintains clarity through scale change(within the range that it would have to change in the application).
          I looked at the documentation of the link you sent, I was wondering if it was possible to set size based on a percentage of the parent widget (QLineEdit in this case)
          Thank you for your help so far!

          1 Reply Last reply Reply Quote 0
          • nagesh
            nagesh last edited by

            @arjun98 said in How do you properly increase QLineEdit increase icon size/:

            ui->searchbar->setClearButtonEnabled(true);
            ui->searchbar->QLineEdit::addAction(QIcon(":/img/icons/icon_search.png"), QLineEdit::LeadingPosition);

            I have tried loading icon to line edit using above code, it's clearly visibile. and image is not blurred.
            try to experiment loading the icon to QLineEdit without any stylesheet being set to it.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post