我是pyqt5的新手,我想弹出一个窗口,让该窗口可以留在主窗口的后面,并且不可单击(类似让新窗口作为另一个处理窗口的样子)
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Demo(QMainWindow):
def __init__(self):
super().__init__()
test_button = QPushButton('test')
test_button.clicked.connect(self.onClick)
self.setCentralWidget(test_button)
def onClick(self):
# dlg = QDialog(self)
dlg = QMainWindow(self)
dlg.setWindowFlag(Qt.WindowStaysOnTopHint, False)
dlg.show()
app = QApplication([])
demo = Demo()
demo.show()
app.exec()
新窗口始终保留在主窗口中,我需要隐藏该窗口。
答案 0 :(得分:0)
void QWidget :: move(int x,int y)
prs = Presentation('blah.pptx')
# To get shapes in your slides
slides = [slide for slide in prs.slides]
shapes = []
for slide in slides:
for shape in slide.shapes:
shapes.append(shape)
def replace_text(self, replacements: dict, shapes: List):
"""Takes dict of {match: replacement, ... } and replaces all matches.
Currently not implemented for charts or graphics.
"""
for shape in shapes:
for match, replacement in replacements.items():
if shape.has_text_frame:
if (shape.text.find(match)) != -1:
text_frame = shape.text_frame
for paragraph in text_frame.paragraphs:
for run in paragraph.runs:
cur_text = run.text
new_text = cur_text.replace(str(match), str(replacement))
run.text = new_text
if shape.has_table:
for row in shape.table.rows:
for cell in row.cells:
if match in cell.text:
new_text = cell.text.replace(match, replacement)
cell.text = new_text
replace_text({'string to replace': 'replacement text'}, shapes)
更新
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Demo(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('Main Window')
test_button = QPushButton('test')
test_button.clicked.connect(self.onClick)
self.setCentralWidget(test_button)
def onClick(self):
# dlg = QDialog(self)
dlg = QMainWindow(self)
dlg.setWindowTitle('Dialog Window')
dlg.move(self.geometry().x() + self.geometry().width() + 30, # <---
self.geometry().y() - 30)
dlg.setWindowFlag(Qt.WindowStaysOnTopHint, False)
dlg.show()
def sizeHint123(self):
return QSize(200, 200)
app = QApplication([])
demo = Demo()
demo.show()
app.exec()