Exemplo n.º 1
0
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()
Exemplo n.º 2
0
    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)