def __init__(self, data, encoding, x0, y0, x1, y1, xsize, ysize): p = QPixmap() p.loadFromData(data, encoding, Qt.AutoColor) w, h = p.width(), p.height() p = p.copy(x0, y0, min(w, x1-x0), min(h, y1-y0)) if p.width() != xsize or p.height() != ysize: p = p.scaled(xsize, ysize, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) QGraphicsPixmapItem.__init__(self, p) self.height, self.width = ysize, xsize self.setTransformationMode(Qt.SmoothTransformation) self.setShapeMode(QGraphicsPixmapItem.BoundingRectShape)
def __init__(self, data, encoding, x0, y0, x1, y1, xsize, ysize): p = QPixmap() p.loadFromData(data, encoding, Qt.AutoColor) w, h = p.width(), p.height() p = p.copy(x0, y0, min(w, x1 - x0), min(h, y1 - y0)) if p.width() != xsize or p.height() != ysize: p = p.scaled(xsize, ysize, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) QGraphicsPixmapItem.__init__(self, p) self.height, self.width = ysize, xsize self.setTransformationMode(Qt.SmoothTransformation) self.setShapeMode(QGraphicsPixmapItem.BoundingRectShape)
def __init__(self,parent=None): super().__init__(parent) # Фаил формы uic.loadUi("forma.ui",self) # Заголовок self.setWindowTitle("Control Program Editor CNC. Ver.4.0.0 ") #ициализируем переменную имя файла self.fileName = "" #имя файла по умолчанию self.fname = "Liste" #Таблица item = QtGui.QStandardItem() self.model = QtGui.QStandardItemModel(self) self.model.appendRow(item) self.model.insertColumn(1) self.model.setHeaderData(0,Qt.Horizontal,"Ось Х ") self.model.setHeaderData(1,Qt.Horizontal,"Ось Z ") self.tableView.resizeColumnsToContents() self.tableView.setModel(self.model) self.tableView.setShowGrid(True) # Кнопки self.Add_Row_Button.clicked.connect(self.AddRow) self.Remove_Row_Button.clicked.connect(self.RemoveRow) self.WriteCsv_Button.clicked.connect(self.WriteCsv) self.Button_Open_File.clicked.connect(self.Open_File) self.NewFile_Button.clicked.connect(self.NewFile) self.Open_Dxf_Button.clicked.connect(self.OpenDXF) self.GenerateProgramButon.clicked.connect(self.GenerateControlProg) self.WriteFile_CProg_Button.clicked.connect(self.WriteControlProg) self.Print_Button.clicked.connect(self.handlePrint) self.Wi_print_Button.clicked.connect(self.handlePreview) self.pushButtonEvolvent.clicked.connect(self.Evolvent) self.pushButton.clicked.connect(self.Oproge) self.checkBoxClearPlot.stateChanged.connect(self.ClearGrafik) self.checkBoxKoc.stateChanged.connect(self.Kos) self.checkBoxKosLev.stateChanged.connect(self.Naklon) self.checkBoxWZ.stateChanged.connect(self.AxisW) self.doubleSpinBox_Z.valueChanged.connect(self.Evolvent) self.doubleSpinBox_m.valueChanged.connect(self.Evolvent) self.doubleSpinBox_a.valueChanged.connect(self.Evolvent) self.doubleSpinBox_ha.valueChanged.connect(self.Evolvent) self.doubleSpinBox_c.valueChanged.connect(self.Evolvent) self.doubleSpinBox_pf.valueChanged.connect(self.Evolvent) self.doubleSpinBox_x.valueChanged.connect(self.Evolvent) self.doubleSpinBox_y.valueChanged.connect(self.Evolvent) self.doubleSpinBox_b.valueChanged.connect(self.Evolvent) self.radioButtonM66.pressed.connect(self.M66) self.radioButtonM6.pressed.connect(self.M6) self.comboBoxProcess.activated[str].connect(self.Open_layer) self.Evolvent() self.label = QLabel(self) pixmap = QPixmap('logo.png') self.label_pixel.setPixmap(pixmap) self.resize(pixmap.width(), pixmap.height())
def displayImage(self, img): self.scene1.clear() pixMap = QPixmap(img) w, h = pixMap.width(), pixMap.height() self.scene1.addPixmap(pixMap) self.view1.fitInView(QRectF(0, 0, w, h), Qt.KeepAspectRatio) self.scene1.update()
def get_image(html): image, width, height, fmt = None, -1, -1, "png" if "<img" in html: raw = html[html.index("<img"):].split(">")[0].split('"') for i, r in enumerate(raw): if "base64" in r: img_txt = r.split(",")[-1].encode(encoding="utf-8") image = QPixmap() image.width() image.height() image.loadFromData(QByteArray.fromBase64(img_txt)) fmt = r.split("image/")[1].split(";")[0] if "width" in r and i + 1 < len(raw): width = int(raw[i + 1]) if "height" in r and i + 1 < len(raw): height = int(raw[i + 1]) return image, width, height, fmt
def open_file(self): directory = QFileDialog.getOpenFileName(self, "选择图片", "./", "(*.jpg)") p = QPixmap(directory[0]) if p.width() > p.height(): p = p.scaledToHeight(self.height() // 2) else: p = p.scaledToWidth(self.width() // 2) self.image.setPixmap(p) self.image.filepath = directory[0]
def paint(self, painter, option, index): name = index.data(Qt.DisplayRole) sz = human_readable(index.data(Qt.UserRole)) pmap = index.data(Qt.UserRole+1) irect = option.rect.adjusted(0, 5, 0, -5) irect.setRight(irect.left() + 70) if pmap is None: pmap = QPixmap(current_container().get_file_path_for_processing(name)) scaled, nwidth, nheight = fit_image(pmap.width(), pmap.height(), irect.width(), irect.height()) if scaled: pmap = pmap.scaled(nwidth, nheight, transformMode=Qt.SmoothTransformation) index.model().setData(index, pmap, Qt.UserRole+1) x, y = (irect.width() - pmap.width())//2, (irect.height() - pmap.height())//2 r = irect.adjusted(x, y, -x, -y) QStyledItemDelegate.paint(self, painter, option, QModelIndex()) painter.drawPixmap(r, pmap) trect = irect.adjusted(irect.width() + 10, 0, 0, 0) trect.setRight(option.rect.right()) painter.save() if option.state & QStyle.State_Selected: painter.setPen(QPen(option.palette.color(option.palette.HighlightedText))) painter.drawText(trect, Qt.AlignVCenter | Qt.AlignLeft, name + '\n' + sz) painter.restore()
def paint(self, painter, option, index): name = index.data(Qt.ItemDataRole.DisplayRole) sz = human_readable(index.data(Qt.ItemDataRole.UserRole)) pmap = index.data(Qt.ItemDataRole.UserRole+1) irect = option.rect.adjusted(0, 5, 0, -5) irect.setRight(irect.left() + 70) if pmap is None: pmap = QPixmap(current_container().get_file_path_for_processing(name)) scaled, nwidth, nheight = fit_image(pmap.width(), pmap.height(), irect.width(), irect.height()) if scaled: pmap = pmap.scaled(nwidth, nheight, transformMode=Qt.TransformationMode.SmoothTransformation) index.model().setData(index, pmap, Qt.ItemDataRole.UserRole+1) x, y = (irect.width() - pmap.width())//2, (irect.height() - pmap.height())//2 r = irect.adjusted(x, y, -x, -y) QStyledItemDelegate.paint(self, painter, option, empty_index) painter.drawPixmap(r, pmap) trect = irect.adjusted(irect.width() + 10, 0, 0, 0) trect.setRight(option.rect.right()) painter.save() if option.state & QStyle.StateFlag.State_Selected: painter.setPen(QPen(option.palette.color(option.palette.HighlightedText))) painter.drawText(trect, Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignLeft, name + '\n' + sz) painter.restore()
class JTracksipButton(QPushButton): ''' class JTracksipButton ''' stateChanged = QtCore.pyqtSignal(bool) def __init__(self, pixmap = None, parent = None): super(JTracksipButton, self).__init__(parent) self.setObjectName('JTracksipButton') self.setCheckable(True) self.setChecked(False) self.isOn = False if pixmap == None: self.pixmap = QPixmap(':/carmonitor/image/button-switch.png') else: self.pixmap = pixmap self.setFixedSize(self.pixmap.width(), self.pixmap.height() / 2) self.pressed.connect(lambda : self.setState(True)) self.released.connect(lambda : self.setState(False)) @QtCore.pyqtSlot() def setState(self, state): if self.isOn != state: self.isOn = state self.setChecked(self.isOn) self.repaint() self.stateChanged.emit(self.isOn) def setSize(self, w, h): self.resize(w, h) self.repaint() def paintEvent(self, e): painter = QPainter(self) h = self.pixmap.height() / 2 painter.drawPixmap(self.rect(), self.pixmap, QRect(0, h * (1 if self.isOn else 0), self.pixmap.width(), h))
def showImage(self, aString = 0): # Create label and add pixmap to it self.myLabel = QLabel(self) myPixmap = QPixmap(aString) self.myLabel.setPixmap(myPixmap) # Create box layout and add elements to it vbox = QVBoxLayout() vbox.addWidget(self.myLabel) self.setLayout(vbox) # Set window size to match size of pixmap self.resize(myPixmap.width(), myPixmap.height()) self.show()
def onSelectionChange (self): warrior = self.model.selectedWarrior[self.model.first_selected] p = QPixmap(warrior.attribs['picture']) diff_V = p.height()/self.picture.height() diff_H = p.width()/self.picture.width() if not p.isNull(): if diff_V < diff_H: p = p.scaledToHeight(self.picture.height()) else: p = p.scaledToWidth(self.picture.width()) self.picture.setPixmap(p) self.Title.setText(warrior.name) self.faction_name.setText(warrior.faction().name) self.empire_name.setText(warrior.empire().name) self.royaume_name.setText(warrior.kingdom().name) self.groupe_name.setText(warrior.groupe().name)
class ImageBox(QWidget): def __init__(self): super(ImageBox, self).__init__() self.img = None self.scaled_img = None self.point = QPoint(0, 0) self.start_pos = None self.end_pos = None self.left_click = False self.scale = 1 def init_ui(self): self.setWindowTitle('ImageBox') def set_image(self, image_path): self.img = QPixmap(image_path) if self.img.width() > 640 or self.img.height() > 640: self.scale = 0.5 def paintEvent(self, e): if self.img: painter = QPainter() painter.begin(self) painter.scale(self.scale, self.scale) painter.drawPixmap(self.point, self.img) painter.end() def mouseMoveEvent(self, e): if self.left_click: self.end_pos = e.pos() - self.start_pos self.point = self.point + self.end_pos self.start_pos = e.pos() self.repaint() def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.left_click = True self.start_pos = e.pos() def mouseReleaseEvent(self, e): if e.button() == Qt.LeftButton: self.left_click = False
def __init__(self): super().__init__() self.setWindowTitle('Image Window') # Create label and add pixmap to it self.myLabel = QLabel(self) myPixmap = QPixmap('testImage.png') self.myLabel.setPixmap(myPixmap) # Create pushbuttons #------------------- # Create pushbutton to rotate image left btnRotateL = QPushButton('Rotate 90° left', self) btnRotateL.clicked.connect(self.rotateL) # Create pushbutton to rotate image left btnRotateR = QPushButton('Rotate 90° right', self) btnRotateR.clicked.connect(self.rotateR) # Create pushbutton to mirror image hirizontally btnMirror = QPushButton('Mirror horizontally', self) btnMirror.clicked.connect(self.mirror) # Create box layout and add elements to it vbox = QVBoxLayout() vbox.addWidget(btnRotateL) vbox.addWidget(btnRotateR) vbox.addWidget(btnMirror) vbox.addWidget(self.myLabel) self.setLayout(vbox) # Set window size to match size of pixmap self.resize(myPixmap.width(),myPixmap.height()) print('Image window initialized')
else: # running live imgDir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'img') ### -- style stuff spmtLogo_file = os.path.join(imgDir, 'splashscreen.png') labelstyle = "QLabel { font-size: 14px; color: purple; font-style: italic; text-align: center;}" barStyle = "QProgressBar::chunk {background: QLinearGradient( x1: 0, y1: 0, x2: 1, y2: 0,stop: 0 #372f43,stop: 0.6 #5c4c7a, stop: 0.8 #663399);border-bottom-right-radius: 7px;border-bottom-left-radius: 7px;border-top: 2px solid #8A2BE2;}" splash_pix = QPixmap(spmtLogo_file) splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint) progressBar = QProgressBar(splash) progressBar.setGeometry(0, splash_pix.height() - 13, splash_pix.width(), 13) progressBar.setStyleSheet(barStyle) progressBar.setAlignment(Qt.AlignRight) label = QLabel(splash) label.setStyleSheet(labelstyle) label.setGeometry((splash_pix.width() - 500) / 2, splash_pix.height() - 40, 500, 20) label.setAlignment(Qt.AlignCenter) progressText = "loading..." label.setText(progressText) splash.show() for i in range(0, 100):
from misc import updateSplash from spmtApp import App # Create App app = QApplication(sys.argv) ### -- style stuff spmtLogo_file = os.path.join(imgDir, 'splashscreen.png') labelstyle = "QLabel { font-size: 14px; color: purple; font-style: italic; text-align: center;}" barStyle = "QProgressBar::chunk {background: QLinearGradient( x1: 0, y1: 0, x2: 1, y2: 0,stop: 0 #372f43,stop: 0.6 #5c4c7a, stop: 0.8 #663399);border-bottom-right-radius: 7px;border-bottom-left-radius: 7px;border-top: 2px solid #8A2BE2;}" splash_pix = QPixmap(spmtLogo_file) splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint) progressBar = QProgressBar(splash) progressBar.setGeometry(0, splash_pix.height()-13, splash_pix.width(), 13) progressBar.setStyleSheet(barStyle) progressBar.setAlignment(Qt.AlignRight) label = QLabel(splash) label.setStyleSheet(labelstyle) label.setGeometry((splash_pix.width()-500)/2, splash_pix.height()-40, 500, 20) label.setAlignment(Qt.AlignCenter) progressText = "loading..." label.setText(progressText) splash.show() for i in range(0, 100): progressBar.setValue(i)