【问题标题】:QComboBox ListView is occuping combobox frameQComboBox ListView 正在占用组合框框架
【发布时间】:2018-06-15 06:30:32
【问题描述】:

comboBox 包含两个条目,当点击combobox 时,listview 占据combobox 的框架。我想要组合框下方的列表视图。样式表如下图:

QComboBox {
border: 1px solid #8F9EAB;
border-radius: 3px;
font: 16pt "Arial";
min-width: 6em;
color: #1B3067;
background-color: rgb(255, 255, 255);
padding-left:10px;
} 
QComboBox:pressed
{
border: 1px solid #1562AD; 
color: rgb(255, 255, 255);
background-color: #87A6D5;
} 
QComboBox:disabled
{
border: 1px solid #BFBFBF; 
color: #BFBFBF;
background-color: rgb(255, 255, 255);
} 
QComboBox::down-arrow
{ 
background-image: url(:/Images/data/img/Images/DOWN_enabled.png);
height: 7px;
width : 13px;
}
QComboBox::drop-down 
{ 
subcontrol-position: top right;
width: 40px;
color: white;
border-left-width: 0px;
border-left-color: #8F9EAB;
border-left-style: solid; 
border-top-right-radius: 3px;
border-bottom-right-radius: 3px; 
}
QComboBox QListView
{
font: 16pt "Arial";
color: rgb(80, 80, 80);
}
QComboBox QAbstractItemView::item 
{
border-bottom: 5px solid white; margin:3px;
}

【问题讨论】:

    标签: c++ qt listview stylesheet qcombobox


    【解决方案1】:

    view()的位置不能用Qt Style Sheet处理,你必须创建一个继承自QComboBox的类并覆盖showPopup()方法,如下所示。

    class ComboBox: public QComboBox{
    public:
        using QComboBox::QComboBox;
    public:
        void showPopup(){
            QComboBox::showPopup();
            QPoint pos = mapToGlobal(QPoint(0, height()));
            view()->parentWidget()->move(pos);
        }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多