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. How do you properly increase QLineEdit increase icon size/

How do you properly increase QLineEdit increase icon size/

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlineediticonsizepixelated
4 Posts 3 Posters 1.8k 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.
  • A Offline
    A Offline
    arjun98
    wrote on 28 Apr 2021, 02:49 last edited by
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Apr 2021, 19:53 last edited by
      #2

      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 30 Apr 2021, 23:28
      0
      • S SGaist
        28 Apr 2021, 19:53

        Hi,

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

        A Offline
        A Offline
        arjun98
        wrote on 30 Apr 2021, 23:28 last edited by
        #3

        @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
        0
        • N Offline
          N Offline
          nagesh
          wrote on 1 May 2021, 01:03 last edited by
          #4

          @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
          0

          2/4

          28 Apr 2021, 19:53

          • Login

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