如何从Python中的字符串中删除特定的节/摘录

时间:2019-04-30 00:57:05

标签: python python-3.x string pyqt

我有一个PyQt样式表,类型为compileSdkVersion 28,在其中将其插入str中以更改CSS属性。我想删除此字符串中的特定代码部分,特别是以下部分:

app.setStyleSheet()

这是整个样式表字符串

QSlider::groove:horizontal {
    background: #32414B;
    border: 1px solid #32414B;
    height: 4px;
    margin: 0px;
    border-radius: 4px;
}

由于我没有从文件中读取内容,因此无法使用stylesheet = ''' /* QWidget ---------------------------------------------------------------- */ QWidget { background-color: #19232D; border: 0px solid #32414B; padding: 0px; color: #F0F0F0; selection-background-color: #1464A0; selection-color: #F0F0F0; } QWidget:disabled { background-color: #19232D; color: #787878; selection-background-color: #14506E; selection-color: #787878; } QWidget:item:selected { background-color: #1464A0; } QWidget:item:hover { background-color: #148CD2; color: #32414B; } /* QMainWindow ------------------------------------------------------------ */ /* This adjusts the splitter in the dock widget, not qsplitter */ QMainWindow::separator { background-color: #32414B; border: 0 solid #19232D; spacing: 0; padding: 2px; } QMainWindow::separator:hover { background-color: #505F69; border: 0px solid #148CD2; } QMainWindow::separator:horizontal { width: 5px; margin-top: 2px; margin-bottom: 2px; image: url(:/qss_icons/rc/Vsepartoolbar.png); } QMainWindow::separator:vertical { height: 5px; margin-left: 2px; margin-right: 2px; image: url(:/qss_icons/rc/Hsepartoolbar.png); } /* QToolTip --------------------------------------------------------------- */ QToolTip { background-color: #148CD2; border: 1px solid #19232D; color: #19232D; padding: 0; /*remove padding, for fix combo box tooltip*/ opacity: 230; /*reducing transparency to read better*/ } /* QStatusBar ------------------------------------------------------------- */ QStatusBar { border: 1px solid #32414B; background: #32414B; /*fixes spyder #9120,#9121*/ } QStatusBar QToolTip { background-color: #148CD2; border: 1px solid #19232D; color: #19232D; padding: 0; /*remove padding, for fix combo box tooltip*/ opacity: 230; /*reducing transparency to read better*/ } QStatusBar QLabel { background-color: transparent; /*fixes spyder #9120,#9121*/ } /* QCheckBox -------------------------------------------------------------- */ QCheckBox { background-color: #19232D; color: #F0F0F0; spacing: 4px; outline: none; padding-top: 4px; padding-bottom: 4px; } QCheckBox:focus { border: none; } QCheckBox QWidget:disabled { background-color: #19232D; color: #787878; } QCheckBox::indicator { margin-left: 4px; width: 16px; height: 16px; } QCheckBox::indicator:unchecked { image: url(:/qss_icons/rc/checkbox_unchecked.png); } QCheckBox::indicator:unchecked:hover, QCheckBox::indicator:unchecked:focus, QCheckBox::indicator:unchecked:pressed { border: none; image: url(:/qss_icons/rc/checkbox_unchecked_focus.png); } QCheckBox::indicator:unchecked:disabled { image: url(:/qss_icons/rc/checkbox_unchecked_disabled.png); } QCheckBox::indicator:checked { image: url(:/qss_icons/rc/checkbox_checked.png); } QCheckBox::indicator:checked:hover, QCheckBox::indicator:checked:focus, QCheckBox::indicator:checked:pressed { border: none; image: url(:/qss_icons/rc/checkbox_checked_focus.png); } QCheckBox::indicator:checked:disabled{ image: url(:/qss_icons/rc/checkbox_checked_disabled.png); } QCheckBox::indicator:indeterminate { image: url(:/qss_icons/rc/checkbox_indeterminate.png); } QCheckBox::indicator:indeterminate:disabled { image: url(:/qss_icons/rc/checkbox_indeterminate_disabled.png); } QCheckBox::indicator:indeterminate:focus, QCheckBox::indicator:indeterminate:hover, QCheckBox::indicator:indeterminate:pressed { image: url(:/qss_icons/rc/checkbox_indeterminate_focus.png); } /* QGroupBox -------------------------------------------------------------- */ QGroupBox { font-weight: bold; border: 1px solid #32414B; border-radius: 4px; padding: 4px; margin-top: 16px; } QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; left: 3px; padding-left: 3px; padding-right: 5px; padding-top: 8px; padding-bottom: 16px; } QGroupBox::indicator { margin-left: 4px; width: 16px; height: 16px; } QGroupBox::indicator { margin-left: 2px; } QGroupBox::indicator:unchecked:hover, QGroupBox::indicator:unchecked:focus, QGroupBox::indicator:unchecked:pressed { border: none; image: url(:/qss_icons/rc/checkbox_unchecked_focus.png); } QGroupBox::indicator:checked:hover, QGroupBox::indicator:checked:focus, QGroupBox::indicator:checked:pressed { border: none; image: url(:/qss_icons/rc/checkbox_checked_focus.png); } QGroupBox::indicator:checked:disabled { image: url(:/qss_icons/rc/checkbox_checked_disabled.png); } QGroupBox::indicator:unchecked:disabled { image: url(:/qss_icons/rc/checkbox_unchecked_disabled.png); } /* QRadioButton ----------------------------------------------------------- */ QRadioButton { background-color: #19232D; color: #F0F0F0; spacing: 0; padding: 0; border: none; outline: none; } QRadioButton:focus { border: none; } QRadioButton:disabled { background-color: #19232D; color: #787878; border: none; outline: none; } QRadioButton QWidget { background-color: #19232D; color: #F0F0F0; spacing: 0px; padding: 0px; outline: none; border: none; } QRadioButton::indicator { border: none; outline: none; margin-bottom: 2px; width: 25px; height: 25px; } QRadioButton::indicator:unchecked { image: url(:/qss_icons/rc/radio_unchecked.png); } QRadioButton::indicator:unchecked:hover, QRadioButton::indicator:unchecked:focus, QRadioButton::indicator:unchecked:pressed { border: none; outline: none; image: url(:/qss_icons/rc/radio_unchecked_focus.png); } QRadioButton::indicator:checked { border: none; outline: none; image: url(:/qss_icons/rc/radio_checked.png); } QRadioButton::indicator:checked:hover, QRadioButton::indicator:checked:focus, QRadioButton::indicator:checked:pressed { border: none; outline: none; image: url(:/qss_icons/rc/radio_checked_focus.png); } QRadioButton::indicator:checked:disabled { outline: none; image: url(:/qss_icons/rc/radio_checked_disabled.png); } QRadioButton::indicator:unchecked:disabled { image: url(:/qss_icons/rc/radio_unchecked_disabled.png); } /* QMenuBar --------------------------------------------------------------- */ QMenuBar { background-color: #32414B; padding: 2px; border: 1px solid #19232D; color: #F0F0F0; } QMenuBar:focus { border: 1px solid #148CD2; } QMenuBar::item { background: transparent; padding: 4px; } QMenuBar::item:selected { padding: 4px; background: transparent; border: 0px solid #32414B; } QMenuBar::item:pressed { padding: 4px; border: 0px solid #32414B; background-color: #148CD2; color: #F0F0F0; margin-bottom: 0px; padding-bottom: 0px; } /* QMenu ------------------------------------------------------------------ */ QMenu { border: 0px solid #32414B; color: #F0F0F0; margin: 0px; } QMenu::separator { height: 2px; background-color: #505F69; color: #F0F0F0; padding-left: 4px; margin-left: 2px; margin-right: 2px; } QMenu::icon { margin: 0px; padding-left:4px; } QMenu::item { padding: 4px 24px 4px 24px; border: 1px transparent #32414B; /* reserve space for selection border */ } QMenu::item:selected { color: #F0F0F0; } QMenu::indicator { width: 12px; height: 12px; padding-left:6px; } /* non-exclusive indicator = check box style indicator (see QActionGroup::setExclusive) */ QMenu::indicator:non-exclusive:unchecked { image: url(:/qss_icons/rc/checkbox_unchecked.png); } QMenu::indicator:non-exclusive:unchecked:selected { image: url(:/qss_icons/rc/checkbox_unchecked_disabled.png); } QMenu::indicator:non-exclusive:checked { image: url(:/qss_icons/rc/checkbox_checked.png); } QMenu::indicator:non-exclusive:checked:selected { image: url(:/qss_icons/rc/checkbox_checked_disabled.png); } /* exclusive indicator = radio button style indicator (see QActionGroup::setExclusive) */ QMenu::indicator:exclusive:unchecked { image: url(:/qss_icons/rc/radio_unchecked.png); } QMenu::indicator:exclusive:unchecked:selected { image: url(:/qss_icons/rc/radio_unchecked_disabled.png); } QMenu::indicator:exclusive:checked { image: url(:/qss_icons/rc/radio_checked.png); } QMenu::indicator:exclusive:checked:selected { image: url(:/qss_icons/rc/radio_checked_disabled.png); } QMenu::right-arrow { margin: 5px; image: url(:/qss_icons/rc/right_arrow.png) } /* QAbstractItemView ------------------------------------------------------ */ QAbstractItemView { alternate-background-color: #19232D; color: #F0F0F0; border: 1px solid #32414B; border-radius: 4px; } QAbstractItemView QLineEdit { padding: 2px; } /* QAbstractScrollArea ---------------------------------------------------- */ QAbstractScrollArea { background-color: #19232D; border: 1px solid #32414B; border-radius: 4px; padding: 4px; color: #F0F0F0; } QAbstractScrollArea:disabled { color: #787878; } /* QScrollArea ------------------------------------------------------------ */ QScrollArea QWidget QWidget:disabled { background-color: #19232D; } /* QScrollBar ------------------------------------------------------------- */ QScrollBar:horizontal { height: 16px; margin: 2px 16px 2px 16px; border: 1px solid #32414B; border-radius: 4px; background-color: #19232D; } QScrollBar::handle:horizontal { background-color: #787878; border: 1px solid #32414B; border-radius: 4px; min-width: 8px; } QScrollBar::handle:horizontal:hover { background-color: #148CD2; border: 1px solid #148CD2; border-radius: 4px; min-width: 8px; } QScrollBar::add-line:horizontal { margin: 0px 0px 0px 0px; border-image: url(:/qss_icons/rc/right_arrow_disabled.png); width: 10px; height: 10px; subcontrol-position: right; subcontrol-origin: margin; } QScrollBar::sub-line:horizontal { margin: 0px 3px 0px 3px; border-image: url(:/qss_icons/rc/left_arrow_disabled.png); height: 10px; width: 10px; subcontrol-position: left; subcontrol-origin: margin; } QScrollBar::add-line:horizontal:hover, QScrollBar::add-line:horizontal:on { border-image: url(:/qss_icons/rc/right_arrow.png); height: 10px; width: 10px; subcontrol-position: right; subcontrol-origin: margin; } QScrollBar::sub-line:horizontal:hover, QScrollBar::sub-line:horizontal:on { border-image: url(:/qss_icons/rc/left_arrow.png); height: 10px; width: 10px; subcontrol-position: left; subcontrol-origin: margin; } QScrollBar::up-arrow:horizontal, QScrollBar::down-arrow:horizontal { background: none; } QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { background: none; } QScrollBar:vertical { background-color: #19232D; width: 16px; margin: 16px 2px 16px 2px; border: 1px solid #32414B; border-radius: 4px; } QScrollBar::handle:vertical { background-color: #787878; border: 1px solid #32414B; min-height: 8px; border-radius: 4px; } QScrollBar::handle:vertical:hover { background-color: #148CD2; border: 1px solid #148CD2; border-radius: 4px; min-height: 8px; } QScrollBar::sub-line:vertical { margin: 3px 0px 3px 0px; border-image: url(:/qss_icons/rc/up_arrow_disabled.png); height: 10px; width: 10px; subcontrol-position: top; subcontrol-origin: margin; } QScrollBar::add-line:vertical { margin: 3px 0px 3px 0px; border-image: url(:/qss_icons/rc/down_arrow_disabled.png); height: 10px; width: 10px; subcontrol-position: bottom; subcontrol-origin: margin; } QScrollBar::sub-line:vertical:hover, QScrollBar::sub-line:vertical:on { border-image: url(:/qss_icons/rc/up_arrow.png); height: 10px; width: 10px; subcontrol-position: top; subcontrol-origin: margin; } QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on { border-image: url(:/qss_icons/rc/down_arrow.png); height: 10px; width: 10px; subcontrol-position: bottom; subcontrol-origin: margin; } QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { background: none; } QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { background: none; } /* QTextEdit--------------------------------------------------------------- */ QTextEdit { background-color: #19232D; color: #F0F0F0; border: 1px solid #32414B; } QTextEdit:hover { border: 1px solid #148CD2; color: #F0F0F0; } QTextEdit:selected { background: #1464A0; color: #32414B; } /* QPlainTextEdit --------------------------------------------------------- */ QPlainTextEdit { background-color: #19232D; color: #F0F0F0; border-radius: 4px; border: 1px solid #32414B; } QPlainTextEdit:hover { border: 1px solid #148CD2; color: #F0F0F0; } QPlainTextEdit:selected { background: #1464A0; color: #32414B; } /* QSizeGrip --------------------------------------------------------------- */ QSizeGrip { image: url(:/qss_icons/rc/sizegrip.png); width: 12px; height: 12px; } /* QStackedWidget --------------------------------------------------------- */ QStackedWidget { padding: 4px; border: 1px solid #32414B; border: 1px solid #19232D; } /* QToolBar --------------------------------------------------------------- */ QToolBar { background-color: #32414B; border-bottom: 1px solid #19232D; padding: 2px; font-weight: bold; } QToolBar QToolButton{ background-color: #32414B; } QToolBar::handle:horizontal { width: 6px; image: url(:/qss_icons/rc/Hmovetoolbar.png); } QToolBar::handle:vertical { height: 6px; image: url(:/qss_icons/rc/Vmovetoolbar.png); } QToolBar::separator:horizontal { width: 3px; image: url(:/qss_icons/rc/Hsepartoolbar.png); } QToolBar::separator:vertical { height: 3px; image: url(:/qss_icons/rc/Vsepartoolbar.png); } QToolButton#qt_toolbar_ext_button { background: #32414B; border: 0px; color: #F0F0F0; image: url(:/qss_icons/rc/right_arrow.png); } /* QAbstractSpinBox ------------------------------------------------------- */ QAbstractSpinBox { background-color: #19232D; border: 1px solid #32414B; color: #F0F0F0; padding-top: 2px; /* This fix 103, 111*/ padding-bottom: 2px; /* This fix 103, 111*/ padding-left: 4px; padding-right: 4px; border-radius: 4px; /* min-width: 5px; removed to fix 109 */ } QAbstractSpinBox:up-button { background-color: transparent #19232D; subcontrol-origin: border; subcontrol-position: top right; border-left: 1px solid #32414B; margin: 1px; } QAbstractSpinBox::up-arrow, QAbstractSpinBox::up-arrow:disabled, QAbstractSpinBox::up-arrow:off { image: url(:/qss_icons/rc/up_arrow_disabled.png); width: 9px; height: 9px; } QAbstractSpinBox::up-arrow:hover { image: url(:/qss_icons/rc/up_arrow.png); } QAbstractSpinBox:down-button { background-color: transparent #19232D; subcontrol-origin: border; subcontrol-position: bottom right; border-left: 1px solid #32414B; margin: 1px; } QAbstractSpinBox::down-arrow, QAbstractSpinBox::down-arrow:disabled, QAbstractSpinBox::down-arrow:off { image: url(:/qss_icons/rc/down_arrow_disabled.png); width: 9px; height: 9px; } QAbstractSpinBox::down-arrow:hover { image: url(:/qss_icons/rc/down_arrow.png); } QAbstractSpinBox:hover{ border: 1px solid #148CD2; color: #F0F0F0; } QAbstractSpinBox:selected { background: #1464A0; color: #32414B; } /* ------------------------------------------------------------------------ */ /* DISPLAYS --------------------------------------------------------------- */ /* ------------------------------------------------------------------------ */ /* QLabel ----------------------------------------------------------------- */ QLabel { background-color: #19232D; border: 0px solid #32414B; padding: 2px; margin: 0px; color: #F0F0F0 } QLabel::disabled { background-color: #19232D; border: 0px solid #32414B; color: #787878; } /* QTextBrowser ----------------------------------------------------------- */ QTextBrowser { background-color: #19232D; border: 1px solid #32414B; color: #F0F0F0; border-radius: 4px; } QTextBrowser:disabled { background-color: #19232D; border: 1px solid #32414B; color: #787878; border-radius: 4px; } QTextBrowser:hover, QTextBrowser:!hover, QTextBrowser::selected, QTextBrowser::pressed { border: 1px solid #32414B; } /* QGraphicsView --------------------------------------------------------- */ QGraphicsView { background-color: #19232D; border: 1px solid #32414B; color: #F0F0F0; border-radius: 4px; } QGraphicsView:disabled { background-color: #19232D; border: 1px solid #32414B; color: #787878; border-radius: 4px; } QGraphicsView:hover, QGraphicsView:!hover, QGraphicsView::selected, QGraphicsView::pressed { border: 1px solid #32414B; } /* QCalendarWidget -------------------------------------------------------- */ QCalendarWidget { border: 1px solid #32414B; border-radius: 4px; } QCalendarWidget:disabled { background-color: #19232D; color: #787878; } /* QLCDNumber ------------------------------------------------------------- */ QLCDNumber { background-color: #19232D; color: #F0F0F0; } QLCDNumber:disabled { background-color: #19232D; color: #787878; } /* QProgressBar ----------------------------------------------------------- */ QProgressBar { background-color: #19232D; border: 1px solid #32414B; color: #F0F0F0; border-radius: 4px; text-align: center; } QProgressBar:disabled { background-color: #19232D; border: 1px solid #32414B; color: #787878; border-radius: 4px; text-align: center; } QProgressBar::chunk { background-color: #1464A0; color: #19232D; border-radius: 4px; } QProgressBar::chunk:disabled { background-color: #14506E; color: #787878; border-radius: 4px; } /* ------------------------------------------------------------------------ */ /* BUTTONS ---------------------------------------------------------------- */ /* ------------------------------------------------------------------------ */ /* QPushButton ------------------------------------------------------------ */ QPushButton { background-color: #505F69 ; border: 1px solid #32414B; color: #F0F0F0; border-radius: 4px; padding: 3px; outline: none; } QPushButton:disabled { background-color: #32414B; border: 1px solid #32414B; color: #787878; border-radius: 4px; padding: 3px; } QPushButton:checked { background-color: #32414B; border: 1px solid #32414B; border-radius: 4px; padding: 3px; outline: none; } QPushButton:checked:disabled { background-color: #19232D; border: 1px solid #32414B; color: #787878; border-radius: 4px; padding: 3px; outline: none; } QPushButton::menu-indicator { subcontrol-origin: padding; subcontrol-position: bottom right; bottom: 4px; } QPushButton:pressed { background-color: #19232D; border: 1px solid #19232D; } QPushButton:hover, QPushButton:checked:hover{ border: 1px solid #148CD2; color: #F0F0F0; } QPushButton:pressed:hover{ border: 1px solid #1464A0; } QPushButton:selected, QPushButton:checked:selected{ background: #1464A0; color: #32414B; } /* QToolButton ------------------------------------------------------------ */ QToolButton { background-color: transparent; border: 1px solid #32414B; border-radius: 4px; margin: 0px; padding: 2px; } QToolButton:checked { background-color: #19232D; border: 1px solid #19232D; } QToolButton:pressed { background-color: #19232D; border: 1px solid #19232D; } QToolButton:disabled { border: 1px solid #32414B; } QToolButton:hover, QToolButton:checked:hover{ border: 1px solid #148CD2; } QToolButton:pressed:hover{ border: 1px solid #1464A0; } /* the subcontrols below are used only in the MenuButtonPopup mode */ QToolButton[popupMode="1"] { padding: 2px; padding-right: 12px; /* only for MenuButtonPopup */ border: 1px solid #32414B; /* make way for the popup button */ border-radius: 4px; } /* The subcontrol below is used only in the InstantPopup or DelayedPopup mode */ QToolButton[popupMode="2"] { padding: 2px; padding-right: 12px; /* only for InstantPopup */ border: 1px solid #32414B; /* make way for the popup button */ } QToolButton::menu-button { padding: 2px; border-radius: 4px; border: 1px solid #32414B; border-top-right-radius: 4px; border-bottom-right-radius: 4px; /* 16px width + 4px for border = 20px allocated above */ width: 16px; outline: none; } QToolButton::menu-button:hover, QToolButton::menu-button:checked:hover { border: 1px solid #148CD2; } QToolButton::menu-indicator { image: url(:/qss_icons/rc/down_arrow.png); top: -8px; /* shift it a bit */ left: -4px; /* shift it a bit */ } QToolButton::menu-arrow { image: url(:/qss_icons/rc/down_arrow.png); } QToolButton::menu-arrow:open { border: 1px solid #32414B; } /* QCommandLinkButton ----------------------------------------------------- */ QCommandLinkButton { background-color: transparent; border: 1px solid #32414B; color: #F0F0F0; border-radius: 4px; padding: 0px; margin: 0px; } QCommandLinkButton:disabled { background-color: transparent; color: #787878; } /* ------------------------------------------------------------------------ */ /* INPUTS - NO FIELDS ----------------------------------------------------- */ /* ------------------------------------------------------------------------ */ /* QCombobox -------------------------------------------------------------- */ QComboBox { border: 1px solid #32414B; border-radius: 4px; selection-background-color: #1464A0; padding-top: 2px; /* This fix #103, #111*/ padding-bottom: 2px; /* This fix #103, #111*/ padding-left: 4px; padding-right: 4px; /* min-width: 75px; removed to fix 109 */ } QComboBox:disabled { background-color: #19232D; color: #787878; } QComboBox:hover{ border: 1px solid #148CD2; } QComboBox:on { selection-background-color: #19232D; } QComboBox QAbstractItemView { background-color: #19232D; border-radius: 4px; border: 1px solid #32414B; selection-color: #148CD2; selection-background-color: #32414B; } QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: top right; width: 20px; border-left-width: 0px; border-left-color: #32414B; border-left-style: solid; border-top-right-radius: 3px; border-bottom-right-radius: 3px; } QComboBox::down-arrow { image: url(:/qss_icons/rc/down_arrow_disabled.png); } QComboBox::down-arrow:on, QComboBox::down-arrow:hover, QComboBox::down-arrow:focus { image: url(:/qss_icons/rc/down_arrow.png); } /* QSlider ---------------------------------------------------------------- */ QSlider:disabled { background: #19232D; } QSlider:focus { border: none; } QSlider::groove:horizontal { background: #32414B; border: 1px solid #32414B; height: 4px; margin: 0px; border-radius: 4px; } QSlider::sub-page:horizontal { background: #1464A0; border: 1px solid #32414B; height: 4px; margin: 0px; border-radius: 4px; } QSlider::sub-page:horizontal:disabled { background: #14506E; } QSlider::handle:horizontal { background: #787878; border: 1px solid #32414B; width: 8px; height: 8px; margin: -8px 0; border-radius: 4px; } QSlider::handle:horizontal:hover { background: #148CD2; border: 1px solid #148CD2; } QSlider::groove:vertical { background: #32414B; border: 1px solid #32414B; width: 4px; margin: 0px; border-radius: 4px; } QSlider::sub-page:vertical { background: #1464A0; border: 1px solid #32414B; width: 4px; margin: 0px; border-radius: 4px; } QSlider::sub-page:vertical:disabled { background: #14506E; } QSlider::handle:vertical { background: #787878; border: 1px solid #32414B; width: 8px; height: 8px; margin: 0 -8px; border-radius: 4px; } QSlider::handle:vertical:hover { background: #148CD2; border: 1px solid #148CD2; } /* QLine ------------------------------------------------------------------ */ QLineEdit { background-color: #19232D; padding-top: 2px; /* This QLineEdit fix 103, 111 */ padding-bottom: 2px; /* This QLineEdit fix 103, 111 */ padding-left: 4px; padding-right: 4px; border-style: solid; border: 1px solid #32414B; border-radius: 4px; color: #F0F0F0; } QLineEdit:disabled { background-color: #19232D; color: #787878; } QLineEdit:hover{ border: 1px solid #148CD2; color: #F0F0F0; } QLineEdit:selected{ background: #1464A0; color: #32414B; } /* QTabWiget -------------------------------------------------------------- */ QTabWidget { padding: 2px; selection-background-color: #32414B; } QTabWidget QFrame{ border: 1px solid #32414B; } QTabWidget::pane { border: 1px solid #32414B; border-radius: 4px; padding: 2px; margin: 0px; } QTabWidget::pane:selected { background-color: #32414B; border: 1px solid #1464A0; } /* QTabBar ---------------------------------------------------------------- */ QTabBar { qproperty-drawBase: 0; border-radius: 4px; margin: 0px; padding: 2px; border: 0; /* left: 5px; move to the right by 5px - removed for fix */ } QTabBar::close-button { border: 0; margin: 2px; padding: 0; image: url(:/qss_icons/rc/close.png); } QTabBar::close-button:hover { image: url(:/qss_icons/rc/close-hover.png); } QTabBar::close-button:pressed { image: url(:/qss_icons/rc/close-pressed.png); } /* QTabBar::tab - selected ----------------------------------------------- */ QTabBar::tab:top:selected:disabled { border-bottom: 3px solid #14506E; color: #787878; background-color: #32414B; } QTabBar::tab:bottom:selected:disabled { border-top: 3px solid #14506E; color: #787878; background-color: #32414B; } QTabBar::tab:left:selected:disabled { border-left: 3px solid #14506E; color: #787878; background-color: #32414B; } QTabBar::tab:right:selected:disabled { border-right: 3px solid #14506E; color: #787878; background-color: #32414B; } /* QTabBar::tab - !selected and disabled ---------------------------------- */ QTabBar::tab:top:!selected:disabled { border-bottom: 3px solid #19232D; color: #787878; background-color: #19232D; } QTabBar::tab:bottom:!selected:disabled { border-top: 3px solid #19232D; color: #787878; background-color: #19232D; } QTabBar::tab:left:!selected:disabled { border-right: 3px solid #19232D; color: #787878; background-color: #19232D; } QTabBar::tab:right:!selected:disabled { border-left: 3px solid #19232D; color: #787878; background-color: #19232D; } ''' 。我已经尝试过使用readline()循环来遍历并检查for是否在其中,但是我不知道如何删除其余的行。如何删除此CSS代码片段,并将其他未修改的CSS作为QSlider::groove:horizontal返回?

str

1 个答案:

答案 0 :(得分:1)

您可以使用.find来获取子字符串的位置,然后Python允许将字符串切片与切片列表相同。因此,如果您想自己完成所有操作,则可以执行以下操作:

def snip_outside_str(text,start_text,end_text):
                start = text.find(start_text)
                end = text[start:].find(end_text) #fails if start_text=end_text
                end = end + start + len(end_text)
                return text[:start]+ text[end:]

stylesheet = 'the really big /*CSS*/ stylesheet string'

def remove_qslider_tick_bug(my_str, start_str='/*', end_str='*/'):

    while my_str.find(start_str)  != -1:
        my_str = snip_outside_str(my_str, start_str, end_str)

    return my_str

警告:这段代码只是解决问题的一个示例,当start_str=end_str或不存在end_str时,它将产生一些奇怪的结果。因此,如果您想使用CSS,可以使用一些库来完成。例如:https://tinycss.readthedocs.io/en/latest/

(免责声明,我不是网络专家,并且从未在愤怒中使用过tinycss)