最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python3+PyQt5 自定義窗口部件--使用窗口部件樣式表的方法

 更新時(shí)間:2019年06月26日 08:41:17   作者:basisworker  
今天小編就為大家分享一篇python3+PyQt5 自定義窗口部件--使用窗口部件樣式表的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

本文借用HTML的css語(yǔ)法,將樣式表應(yīng)用到窗口部件。這里只是個(gè)簡(jiǎn)單的例子,實(shí)際上樣式表的語(yǔ)法很豐富。

以下類(lèi)似于css:

 StyleSheet = """
QComboBox { color: darkblue; }
QLineEdit { color: darkgreen; }
QLineEdit[mandatory="true"] { #mandatory="true"時(shí),QLineEdit的樣式會(huì)變化
 background-color: rgb(255, 255, 127);
 color: darkblue;
}

如果在選擇器的前面加上一個(gè)句點(diǎn),比如.QLineEdit,則選擇器就會(huì)只應(yīng)用于指定的類(lèi),而不會(huì)應(yīng)用于這個(gè)類(lèi)的子類(lèi)。如果要求選擇器僅用于某一特定窗口部件,則可以對(duì)該窗口部件調(diào)用setObjectName(),然后用該名字作為選擇器的一部分。比如,如果有一個(gè)按鈕,其對(duì)象名字是“findButton”,則應(yīng)用于這個(gè)按鈕的選擇器就應(yīng)該是QpushButton#findButton。有些窗口部件會(huì)有一些子控件。例如QComboBox會(huì)有一個(gè)箭頭子控件,用戶(hù)通過(guò)點(diǎn)擊這個(gè)箭頭來(lái)看到下拉列表。子控件可以指定為選擇器的一部分–例如,QComboBox::drop-down。偽狀態(tài)可以用一個(gè)冒號(hào)指定–例如,QCheckBox::checked.

#!/usr/bin/env python3

import sys
from PyQt5.QtWidgets import (QApplication, QComboBox, QDialog,
  QDialogButtonBox, QGridLayout, QLabel, QLineEdit, QVBoxLayout)


class ContactDlg(QDialog):

 StyleSheet = """
QComboBox { color: darkblue; }
QLineEdit { color: darkgreen; }
QLineEdit[mandatory="true"] {
 background-color: rgb(255, 255, 127);
 color: darkblue;
}
"""

 def __init__(self, parent=None):
  super(ContactDlg, self).__init__(parent)

  forenameLabel = QLabel("&Forename:")
  self.forenameEdit = QLineEdit()
  forenameLabel.setBuddy(self.forenameEdit)
  surnameLabel = QLabel("&Surname:")
  self.surnameEdit = QLineEdit()
  surnameLabel.setBuddy(self.surnameEdit)
  categoryLabel = QLabel("&Category:")
  self.categoryComboBox = QComboBox()
  categoryLabel.setBuddy(self.categoryComboBox)
  self.categoryComboBox.addItems(["Business", "Domestic",
          "Personal"])
  companyLabel = QLabel("C&ompany:")
  self.companyEdit = QLineEdit()
  companyLabel.setBuddy(self.companyEdit)
  addressLabel = QLabel("A&ddress:")
  self.addressEdit = QLineEdit()
  addressLabel.setBuddy(self.addressEdit)
  phoneLabel = QLabel("&Phone:")
  self.phoneEdit = QLineEdit()
  phoneLabel.setBuddy(self.phoneEdit)
  mobileLabel = QLabel("&Mobile:")
  self.mobileEdit = QLineEdit()
  mobileLabel.setBuddy(self.mobileEdit)
  faxLabel = QLabel("Fa&x:")
  self.faxEdit = QLineEdit()
  faxLabel.setBuddy(self.faxEdit)
  emailLabel = QLabel("&Email:")
  self.emailEdit = QLineEdit()
  emailLabel.setBuddy(self.emailEdit)
  self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|
           QDialogButtonBox.Cancel)
  addButton = self.buttonBox.button(QDialogButtonBox.Ok)
  addButton.setText("&Add")
  addButton.setEnabled(False)

  grid = QGridLayout()
  grid.addWidget(forenameLabel, 0, 0)
  grid.addWidget(self.forenameEdit, 0, 1)
  grid.addWidget(surnameLabel, 0, 2)
  grid.addWidget(self.surnameEdit, 0, 3)
  grid.addWidget(categoryLabel, 1, 0)
  grid.addWidget(self.categoryComboBox, 1, 1)
  grid.addWidget(companyLabel, 1, 2)
  grid.addWidget(self.companyEdit, 1, 3)
  grid.addWidget(addressLabel, 2, 0)
  grid.addWidget(self.addressEdit, 2, 1, 1, 3)
  grid.addWidget(phoneLabel, 3, 0)
  grid.addWidget(self.phoneEdit, 3, 1)
  grid.addWidget(mobileLabel, 3, 2)
  grid.addWidget(self.mobileEdit, 3, 3)
  grid.addWidget(faxLabel, 4, 0)
  grid.addWidget(self.faxEdit, 4, 1)
  grid.addWidget(emailLabel, 4, 2)
  grid.addWidget(self.emailEdit, 4, 3)
  layout = QVBoxLayout()
  layout.addLayout(grid)
  layout.addWidget(self.buttonBox)
  self.setLayout(layout)

  self.lineedits = (self.forenameEdit, self.surnameEdit,
    self.companyEdit, self.phoneEdit, self.emailEdit)
  for lineEdit in self.lineedits:
   lineEdit.setProperty("mandatory", True)
   lineEdit.textEdited.connect(self.updateUi)
  self.categoryComboBox.activated.connect(self.updateUi)

  self.buttonBox.accepted.connect(self.accept)
  self.buttonBox.rejected.connect(self.reject)
  self.setStyleSheet(ContactDlg.StyleSheet)
  self.setWindowTitle("Add Contact")


 def updateUi(self):
  mandatory = bool(self.companyEdit.property("mandatory"))
  if self.categoryComboBox.currentText() == "Business":
   if not mandatory:
    self.companyEdit.setProperty("mandatory", True)
  elif mandatory:
   self.companyEdit.setProperty("mandatory", False)
  if (mandatory !=
   bool(self.companyEdit.property("mandatory"))):
   self.setStyleSheet(ContactDlg.StyleSheet)

  enable = True
  for lineEdit in self.lineedits:
   if (bool(lineEdit.property("mandatory")) and
    not lineEdit.text()):
    enable = False
    break
  self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)


if __name__ == "__main__":
 app = QApplication(sys.argv)
 form = ContactDlg()
 form.show()
 app.exec_()

運(yùn)行結(jié)果:

以上這篇python3+PyQt5 自定義窗口部件--使用窗口部件樣式表的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

  • Opencv常見(jiàn)圖像格式Data Type及代碼實(shí)例

    Opencv常見(jiàn)圖像格式Data Type及代碼實(shí)例

    這篇文章主要介紹了Opencv常見(jiàn)圖像格式Data Type及代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 2019 Python最新面試題及答案16道題

    2019 Python最新面試題及答案16道題

    這篇文章主要介紹了2019 Python最新面試題及答案16道題 ,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-04-04
  • pytest注解使用小結(jié)

    pytest注解使用小結(jié)

    本文介紹了pytest測(cè)試框架中常用的一些裝飾器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2025-02-02
  • 執(zhí)行Python程序時(shí)模塊報(bào)錯(cuò)問(wèn)題

    執(zhí)行Python程序時(shí)模塊報(bào)錯(cuò)問(wèn)題

    這篇文章主要介紹了執(zhí)行Python程序時(shí)模塊報(bào)錯(cuò)問(wèn)題及解決方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • Python contextlib模塊使用示例

    Python contextlib模塊使用示例

    這篇文章主要介紹了Python contextlib模塊使用示例,本文著重使用contextlib模塊產(chǎn)生一個(gè)上下文管理器,需要的朋友可以參考下
    2015-02-02
  • python的ImageTk.PhotoImage大坑及解決

    python的ImageTk.PhotoImage大坑及解決

    這篇文章主要介紹了python的ImageTk.PhotoImage大坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Python批量生成特定尺寸圖片及圖畫(huà)任意文字的實(shí)例

    Python批量生成特定尺寸圖片及圖畫(huà)任意文字的實(shí)例

    今天小編就為大家分享一篇Python批量生成特定尺寸圖片及圖畫(huà)任意文字的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01
  • pytorch 多分類(lèi)問(wèn)題,計(jì)算百分比操作

    pytorch 多分類(lèi)問(wèn)題,計(jì)算百分比操作

    這篇文章主要介紹了pytorch 多分類(lèi)問(wèn)題,計(jì)算百分比操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • Python使用Slider組件實(shí)現(xiàn)調(diào)整曲線參數(shù)功能示例

    Python使用Slider組件實(shí)現(xiàn)調(diào)整曲線參數(shù)功能示例

    這篇文章主要介紹了Python使用Slider組件實(shí)現(xiàn)調(diào)整曲線參數(shù)功能,結(jié)合實(shí)例形式分析了Python使用matplotlib與Slider組件進(jìn)行圖形繪制相關(guān)操作技巧,需要的朋友可以參考下
    2019-09-09
  • Python 生成VOC格式的標(biāo)簽實(shí)例

    Python 生成VOC格式的標(biāo)簽實(shí)例

    這篇文章主要介紹了Python 生成VOC格式的標(biāo)簽實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03

最新評(píng)論

吐鲁番市| 营口市| 开化县| 英德市| 清水县| 醴陵市| 潼关县| 鄂托克前旗| 垣曲县| 乐清市| 扶沟县| 临海市| 繁昌县| 乐清市| 手游| 中宁县| 濮阳市| 杨浦区| 宁晋县| 澳门| 怀柔区| 获嘉县| 齐齐哈尔市| 黄石市| 乌拉特前旗| 武清区| 雅安市| 石狮市| 耒阳市| 三河市| 台安县| 沂南县| 德州市| 南部县| 永善县| 正镶白旗| 会东县| 离岛区| 城市| 汝城县| 潮安县|