• 1589阅读
  • 0回复

[讨论]关于QComboBox鼠标点击时,出现选项错位的现象 [复制链接]

上一主题 下一主题
离线lwei24
 

只看楼主 倒序阅读 楼主  发表于: 2021-03-09
各位大佬,请问为什么QComboBox点击选项时,选项会出现错位的现象呢?具体代码如下:
    m_labelLanguage = new QLabel(LABEL_SOFTWARE_LANGUAGE_INFO, this);
    m_labelLanguage->setAlignment(Qt::AlignCenter);
    m_labelLanguage->setStyleSheet("QLabel{border-radius:0px;background-repeat:no-repeat;border:none;color:black;font:14px ""SimHei"";}");
    m_labelLanguage->resize(this->width()*30/100, this->height()*20/100);
    m_labelLanguage->move(this->width()*5/100, this->height()*23/100);

    m_comboLanguage = new QComboBox(this);
    m_comboLanguage->setStyleSheet("QComboBox{font-family:'SimHei';font-size:9; border:1px solid lightgray;}"
                                   "QComboBox QAbstractItemView::item {min-height: 16px;}"
                                   "QComboBox::drop-down{border-left-width: 1px;border-left-color: lightgray;border-left-style: solid; border-top-right-radius: 3px;border-bottom-right-radius: 3px;subcontrol-origin: padding;subcontrol-position: top right; width:20px;}"
                                   "QComboBox::down-arrow{image:url(:/res/pwd/arrowDown01.png)}"
                                   "QComboBox::down-arrow:hover{image:url(:/res/pwd/arrowDown01.png)}"
                                   "QComboBox::down-arrow:pressed{image:url(:/res/pwd/arrowDown01.png)}");
    m_comboLanguage->addItem(COMBOBOX_SIMCHINESE_INFO);
    m_comboLanguage->addItem(COMBOBOX_TRACHINESE_INFO);
    m_comboLanguage->addItem(COMBOBOX_ENGLISH_INFO);
    QStyledItemDelegate *delegate1 = new QStyledItemDelegate(this);
    m_comboLanguage->setItemDelegate(delegate1);
    m_comboLanguage->resize(this->width()*40/100, this->height()*11/100);
    m_comboLanguage->move(this->width()*4/100 + m_labelLanguage->width(), this->height()*28/100);

    m_labelEncryptLevel = new QLabel(LABEL_ENCRYPT_LEVEL_INFO, this);
    m_labelEncryptLevel->setAlignment(Qt::AlignCenter);
    m_labelEncryptLevel->setStyleSheet("QLabel{border-radius:0px;background-repeat:no-repeat;border:none;color:black;font:14px ""SimHei"";}");
    m_labelEncryptLevel->resize(this->width()*30/100, this->height()*20/100);
    m_labelEncryptLevel->move(this->width()*5/100, this->height()*40/100);

    m_comboEncryptPsi = new QComboBox(this);
    m_comboEncryptPsi->setStyleSheet("QComboBox{font-family:'SimHei';font-size:9; border:1px solid lightgray;}"
                                     "QComboBox QAbstractItemView::item {min-height: 16px;}"
                                     "QComboBox::drop-down{border-left-width: 1px;border-left-color: lightgray;border-left-style: solid; border-top-right-radius: 3px;border-bottom-right-radius: 3px;subcontrol-origin: padding;subcontrol-position: top right; width:20px;}"
                                     "QComboBox::down-arrow{image:url(:/res/pwd/arrowDown01.png)}"
                                     "QComboBox::down-arrow:hover{image:url(:/res/pwd/arrowDown01.png)}"
                                     "QComboBox::down-arrow:pressed{image:url(:/res/pwd/arrowDown01.png)}");
    m_comboEncryptPsi->addItem(COMBOBOX_DATAHIDE_INFO);
    m_comboEncryptPsi->addItem(COMBOBOX_DATAENCRYPT_INFO);
    QStyledItemDelegate *delegate2 = new QStyledItemDelegate(this);
    m_comboEncryptPsi->setItemDelegate(delegate2);
    m_comboEncryptPsi->resize(this->width()*40/100, this->height()*11/100);
    m_comboEncryptPsi->move(this->width()*4/100 + m_labelEncryptLevel->width(), this->height()*45/100);

    m_labelEncrypAlgorithm = new QLabel(LABEL_ENCRYPT_ALGORITHM_INFO, this);
    m_labelEncrypAlgorithm->setAlignment(Qt::AlignCenter);
    m_labelEncrypAlgorithm->setStyleSheet("QLabel{border-radius:0px;background-repeat:no-repeat;border:none;color:black;font:14px ""SimHei"";}");
    m_labelEncrypAlgorithm->resize(this->width()*30/100, this->height()*20/100);
    m_labelEncrypAlgorithm->move(this->width()*5/100, this->height()*57/100);

    m_comboAlgorithm = new QComboBox(this);
    m_comboAlgorithm->setStyleSheet("QComboBox{font-family:'SimHei';font-size:9; border:1px solid lightgray;}"
                                    "QComboBox QAbstractItemView::item {min-height: 16px;}"
                                    "QComboBox::drop-down{border-left-width: 1px;border-left-color: lightgray;border-left-style: solid; border-top-right-radius: 3px;border-bottom-right-radius: 3px;subcontrol-origin: padding;subcontrol-position: top right; width:20px;}"
                                    "QComboBox::down-arrow{image:url(:/res/pwd/arrowDown01.png)}"
                                    "QComboBox::down-arrow:hover{image:url(:/res/pwd/arrowDown01.png)}"
                                    "QComboBox::down-arrow:pressed{image:url(:/res/pwd/arrowDown01.png)}");
    m_comboAlgorithm->addItem(ITEM_ALGO_AES256_INFO);
    m_comboAlgorithm->addItem(ITEM_ALGO_SM4_INFO);
    QStyledItemDelegate *delegate3 = new QStyledItemDelegate(this);
    m_comboAlgorithm->setItemDelegate(delegate3);
    m_comboAlgorithm->resize(this->width()*40/100, this->height()*11/100);
    m_comboAlgorithm->move(this->width()*4/100 + m_labelEncrypAlgorithm->width(), this->height()*62/100);


快速回复
限100 字节
 
上一个 下一个