Results 1 to 6 of 6

Thread: Search bar - layout

  1. #1
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Exclamation Search bar - layout

    Hello
    Someone can tell me how I can do a search bar that looks like this -> barraPesquisa.png

    Regards,
    Daniel Sousa

  2. #2
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Search bar - layout

    it the designer, right click on widget, change stylesheet,
    one example for rounded border

    #frame
    {
    border: 5px solid gray;
    border-radius: 10px;
    }

    for the rest...
    experiment with stylesheets

  3. #3
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Search bar - layout

    Quote Originally Posted by davidovv View Post
    it the designer, right click on widget, change stylesheet,
    one example for rounded border

    #frame
    {
    border: 5px solid gray;
    border-radius: 10px;
    }

    for the rest...
    experiment with stylesheets
    But how do I put a QLineEdit with so round?

  4. #4
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Search bar - layout

    read this one for better explanation, and better idea what can you do
    http://doc.qt.io/qt-4.8/stylesheet-examples

    You can also look at demos and examples

  5. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Search bar - layout

    Like davidovv said, setStyleSheet() and border-radius is a way of creating rounded corners.

    But if you want to have the search bar exacly as the one on the picture, you will need more complex widget than simple line edit.

  6. #6
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Search bar - layout

    Quickly, you can create a custom widget that inherits QLineEdit.
    Then have a QHBoxLayout inside with all those components, something like this:

    Qt Code:
    1. QLabel magnifierIcon = new QLabel(this);
    2. magnifierIcon->setFocusPolicy(Qt::NoFocus);
    3. magnifierIcon->setObjectName("searchMagnifierIcon");
    4. magnifierIcon->setPixmap("qrc:/images/magnifier.png");
    5.  
    6. QLabel voiceInput = new QLabel(this);
    7. voiceInput->setObjectName("voiceInputIcon");
    8. voiceInput->setPixmap("qrc:/images/voiceinput.png");
    9.  
    10. QHBoxLayout *lineEditLayout = new QHBoxLayout;
    11. lineEditLayout->setMargin(0);
    12. lineEditLayout->addWidget(magnifierIcon, 0, Qt::AlignLeft|Qt::AlignVCenter);
    13. lineEditLayout->addStretch();
    14. lineEditLayout->addWidget(voiceInput, 0, Qt::AlignRight|Qt::AlignVCenter);
    15. // Set the QLineEdit layout
    16. setLayout(lineEditLayout);
    To copy to clipboard, switch view to plain text mode 

    Ofcourse the magnifierIcon could be a QComboBox or a QToolButton.

    Then your stylesheet would be something like this:

    Qt Code:
    1. {
    2. border: 1px solid #D2D2D2;
    3. padding-left: 15px; /* must have padding on the left, so it gives some space for the magnifier icon */
    4. padding-right: 15px; /* must have padding on the right, so it gives some space for the voice input icon */
    5. border-radius: 8px;
    6. }
    7. QLineEdit #searchMagnifierIcon
    8. {
    9. border: 0px;
    10. padding: 0px;
    11. width: 13px; /* width of the magnifier icon */
    12. height: 12px; /* height of the magnifier icon */
    13. margin-left: 5px;
    14. }
    To copy to clipboard, switch view to plain text mode 

    I hope this helps.
    Last edited by tferreira; 17th May 2012 at 12:56.

Similar Threads

  1. Replies: 6
    Last Post: 13th February 2011, 23:06
  2. Hiding Layout item - Layout does not use available space
    By Asperamanca in forum Qt Programming
    Replies: 0
    Last Post: 27th January 2011, 09:51
  3. Replies: 0
    Last Post: 12th December 2010, 05:09
  4. Replies: 0
    Last Post: 25th May 2009, 10:00
  5. Replies: 7
    Last Post: 15th June 2007, 16:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.