zoukankan      html  css  js  c++  java
  • 每个QWidget都有contentsMargins函数,善用QMargins

    m_pSearchLineEdit = new QLineEdit();
    QPushButton *pSearchButton = new QPushButton(this);
    
    pSearchButton->setCursor(Qt::PointingHandCursor);
    pSearchButton->setFixedSize(22, 22);
    pSearchButton->setToolTip(QStringLiteral("搜索"));
    pSearchButton->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)}");
    
    //防止文本框输入内容位于按钮之下
    QMargins margins = m_pSearchLineEdit->textMargins();
    m_pSearchLineEdit->setTextMargins(margins.left(), margins.top(), pSearchButton->width(), margins.bottom());
    m_pSearchLineEdit->setPlaceholderText(QStringLiteral("请输入搜索内容"));
    
    QHBoxLayout *pSearchLayout = new QHBoxLayout();
    pSearchLayout->addStretch();
    pSearchLayout->addWidget(pSearchButton);
    pSearchLayout->setSpacing(0);
    pSearchLayout->setContentsMargins(0, 0, 0, 0);
    m_pSearchLineEdit->setLayout(pSearchLayout);
    
    connect(pSearchButton, SIGNAL(clicked(bool)), this, SLOT(search()));

    http://blog.csdn.net/u011012932/article/details/50357523

    http://doc.qt.io/qt-5/qwidget.html#contentsMargins

  • 相关阅读:
    2019浙江理工校赛有感
    问题 G: 跳马棋
    问题 H: 象棋对局胜负
    问题 C: 远离原点
    问题 B: 合并车厢
    Hibernate 异常汇总
    设计模式
    1.2.1.2.1.12.34.3.1.34.1.2
    数据结构和算法之 查找
    数据结构和算法之排序算法
  • 原文地址:https://www.cnblogs.com/findumars/p/5962426.html
Copyright © 2011-2022 走看看