Qt Custom Search box

Source: Internet
Author: User

Qt Custom Search box
Brief Introduction

The search box is frequently used. Such as browser search and Windows Resource Manager search.

Of course, there is no pressure on Qt implementation, as long as the idea is clear, it can be done in minutes.

Brief Analysis of results details download Coding source code


Detail Analysis

The following steps are required:

Combined implementation, input box + button event Association to get input text for text search

To be more humane and easy to use, we need to pay attention to the following details:

The text in the input box cannot be under the button. If there is no text in the input box, a friendly prompt button must be provided without text description. Generally, A ToolTip prompt button style must be provided-normal, slide, and pressed, and move the mouse over the mouse style hand,

All of these are clear, so we can quickly implement a search box.


Search box implementation

M_shortarchlineedit = new QLineEdit (); QPushButton * extends archbutton = new QPushButton (this); your archbutton-> setCursor (Qt: PointingHandCursor); your archbutton-> setFixedSize (22, 22 ); export archbutton-> setToolTip (QStringLiteral ("Search"); export archbutton-> setStyleSheet ("QPushButton {border-image: url (:/images/icon_search_normal); background: transparent ;} \ QPushButton: hover {border-image: url (:/images/icon_search_hover)} \ QPushButton: pressed {border-image: url (:/images/icon_search_press )}"); // prevent text box content from being placed under the button QMargins margins = m_shortarchlineedit-> textMargins (); m_shortarchlineedit-> setTextMargins (margins. left (), margins. top (), repeated archbutton-> width (), margins. bottom (); m_shortarchlineedit-> setPlaceholderText (QStringLiteral ("Enter search content"); QHBoxLayout * specify archlayout = new QHBoxLayout (); then archlayout-> addStretch (); revoke archlayout-> addWidget (shortarchbutton); Revoke archlayout-> setSpacing (0); Revoke archlayout-> setContentsMargins (0, 0, 0, 0); m_shortarchlineedit-> setLayout (shortarchlayout ); connect (shortarchbutton, SIGNAL (clicked (bool), this, SLOT (search ()));

Slot function implementation

Void Widget: search () {QString strText = m_shortarchlineedit-> text (); if (! StrText. isEmpty () {QMessageBox: information (this, QStringLiteral ("Search"), QStringLiteral ("search content: % 1"). arg (strText ));}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.