class ImagePlayer(QWidget): def __init__(self, filename, title, parent=None): QWidget.__init__(self, parent) # Load the file into a QMovie self.movie = QMovie(filename, QByteArray(), self) print(filename) size = self.movie.scaledSize() self.setGeometry(200, 200, size.width(), size.height()) self.setWindowTitle(title) self.movie_screen = QLabel() # Make label fit the gif self.movie_screen.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.movie_screen.setAlignment(Qt.AlignCenter) self.btn_ex = QPushButton() self.btn_ex.setFixedWidth(100) self.btn_ex.setFixedHeight(100) # self.btn_ex.setIcon(QIcon("image/ex_stu.gif")) self.btn_ex.setStyleSheet("background-color: rgba(255,255,255,20);") self.btn_ex.setIcon(QIcon("image/smile.png")) self.btn_ex.setIconSize(QSize(80,80)) self.btn_ex.setFlat(True) popMenu = QMenu(self) entry1 = popMenu.addAction("正确") # self.connect(entry1,SIGNAL('triggered()'), lambda item=item[0]: self.answerRight(item)) entry2 = popMenu.addAction("错误") # self.connect(entry2,SIGNAL('triggered()'), lambda item=item[0]: self.answerWrong(item)) entry3 = popMenu.addAction("替换") # self.connect(entry3,SIGNAL('triggered()'), lambda item=item[0]: self.resetStudent(item)) self.btn_ex.setMenu(popMenu) # Create the layout main_layout = QVBoxLayout() main_layout.addWidget(self.movie_screen) # main_layout.addWidget(self.btn_ex) self.setLayout(main_layout) # Add the QMovie object to the label self.movie.setCacheMode(QMovie.CacheAll) # self.movie.setSpeed(100) self.movie_screen.setMovie(self.movie) self.movie_screen.setLayout(QHBoxLayout()) self.movie_screen.layout().addWidget(self.btn_ex) popMenu = QMenu(self) entry1 = popMenu.addAction("正确") # self.movie_screen.setMenu(popMenu) self.movie.start()
def addCutMark(self,frame,cutEntry,rowIndex): item = QListWidgetItem() img = CVImage(frame).scaled(self.ui_VideoFrame.imageRatio*SIZE_ICON, SIZE_ICON) pix = QtGui.QPixmap.fromImage(img) item.setIcon(QIcon(pix)) if cutEntry.isStartMode(): item.setBackgroundColor(QColor(224,255,224)) else: item.setBackgroundColor(QColor(255,224,224)) self.ui_List.insertItem(rowIndex,item) text = "%s <br> F: %s<br> T: %s" %(cutEntry.modeString,str(cutEntry.frameNumber),str(cutEntry.getTimeString())) marker = QLabel(text) marker.setWordWrap(True) marker.layout() self.ui_List.setItemWidget(item,marker) self.ui_List.setIconSize(QSize(SIZE_ICON,SIZE_ICON)) #Forces an update! self.ui_List.setCurrentItem(item)
def genOneTab(self, tabtitle="", tabbtn="", tabnums="", strwhere = "where studentsn like '03%' "): # tabtitle.setFixedHeight(40) # tabtitle.setFixedWidth(160) tabtitle.setFont(QFont('Courier New', 20)) tabtitle.setText("随堂提问演板") tabtitle.setStyleSheet("border: 3px solid blue;\ border-radius: 6px; \ padding: 1px 18px 1px 20px;\ min-width: 8em;") tabtitle.setMinimumHeight(50); titleLayout = QHBoxLayout() titleLayout.addWidget(tabtitle) titleLayout.setAlignment(tabtitle, Qt.AlignCenter) btnlayout = QGridLayout() cur = conn.cursor() strsql = "select studentsn, studentname from student " + strwhere cur.execute(strsql) tmpnum = 0 for item in cur.fetchall(): irow = tmpnum // 7 icol = tmpnum % 7 tmpnum += 1 btnlayout.setRowMinimumHeight(irow, 80) tmpbtn = QPushButton(item[1]) # tmpbtn.setFixedHeight(20) tmpbtn.setSizePolicy(QSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)) # tmpbtn.setStyleSheet("border: 1px solid rgb(255,255,255,0);background-color: rgba(255,255,255,20);font-size:16px;") tmpbtn.setFlat(True) popMenu = QMenu(self) entry1 = popMenu.addAction("正确") self.connect(entry1,SIGNAL('triggered()'), lambda item=item[0]: self.answerRight(item)) entry2 = popMenu.addAction("错误") self.connect(entry2,SIGNAL('triggered()'), lambda item=item[0]: self.answerWrong(item)) entry3 = popMenu.addAction("替换") self.connect(entry3,SIGNAL('triggered()'), lambda item=item[0]: self.resetStudent(item)) tmpbtn.setMenu(popMenu) tmpbtn.setAutoDefault(False) self.btngroup.addButton(tmpbtn, int(item[0])) tmpmovie = QMovie('image/ex_stu.gif', QByteArray(), self) tmplabel = QLabel() tmplabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) tmplabel.setAlignment(Qt.AlignCenter) tmplabel.setMovie(tmpmovie) tmplabel.setScaledContents(True) tmplabel.setLayout(QHBoxLayout()) tmplabel.layout().setContentsMargins(0,0,0,0) # tmplabel.setStyleSheet("border: 1px solid rgb(255,255,255,0);background-color: rgba(255,255,255,20);font-size:16px;") tmplabel.layout().addWidget(tmpbtn) tmpmovie.start() tmpmovie.stop() btnlayout.addWidget(tmplabel, irow, icol) tabbtn.setIcon(QIcon("image/start.png")) tabbtn.setStyleSheet("border: 5px solid yellow;") tabbtn.setFixedHeight(40) tabbtn.setFixedWidth(100) tabbtn.setFont(QFont('宋体', 20)) # tabnums.setFixedHeight(45) # tabnums.setFixedWidth(60) tabnums.setFont(QFont('Courier New', 20)) tabnums.setStyleSheet("border: 5px solid blue; color:red;font-weight:bold;font-size:26px;\ border-radius: 6px; \ padding: 1px 1px 1px 1px;\ min-width: 2em; ") tabnums.setEditable(True) tabnums.lineEdit().setReadOnly(True); tabnums.lineEdit().setAlignment(Qt.AlignCenter); model = tabnums.model() for row in list(range(1, 7)): item = QStandardItem(str(row)) item.setTextAlignment(Qt.AlignCenter) item.setForeground(QColor('red')) item.setBackground(QColor(0,200,50, 130)) model.appendRow(item) tabnums.setCurrentIndex(2) # tabnums.setStyleSheet ("QComboBox::drop-down {border-width: 100px;}") # tabnums.setStyleSheet ("QComboBox::down-arrow {image: url(image/downarrow.png);top: 10px;left: 1px;}") bottomlayout = QHBoxLayout() bottomlayout.setSizeConstraint(QLayout.SetFixedSize) bottomlayout.addStretch(10) bottomlayout.addWidget(tabbtn) bottomlayout.setSpacing(5) bottomlayout.addWidget(tabnums) cur.close() return(titleLayout, btnlayout, bottomlayout)