Want to Join Us ?

you'll be able to discuss, share and send private messages.

Python QT Creating stylesheet one way

Discussion in 'Plugins developement QT' started by storm shadow, Jul 22, 2014.

Share This Page

  1. storm shadow

    Techbliss Owner Admin Ida Pro Expert Developer

    gonna spice up a QT plugin

    gonna make basic form with two buttons

    open up QT designer

    drag two buttons to the form

    right click button and choose stylesheet

    [​IMG]

    paste code

    PHP:
    QPushButton {
    color: #333;
    border: 2px solid #555;
    border-radius: 11px;
    padding: 5px;
    background: qradialgradient(cx: 0.3, cy: -0.4,
    fx: 0.3, fy: -0.4,
    radius: 1.35, stop: 0 #fff, stop: 1 #888);
    min-width: 80px;
    }
     
    QPushButton:hover {
    background: qradialgradient(cx: 0.3, cy: -0.4,
    fx: 0.3, fy: -0.4,
    radius: 1.35, stop: 0 #fff, stop: 1 #bbb);
    }
     
    QPushButton:pressed {
    background: qradialgradient(cx: 0.4, cy: -0.1,
    fx: 0.4, fy: -0.1,
    radius: 1.35, stop: 0 #fff, stop: 1 #ddd);
    }
    [​IMG]

    explaination button shape and color

    PHP:
    QPushButton {
     
    color: #333;

    border: 2px solid #555;

    border-radius: 11px;
     
    padding: 5px;
     
    background: qradialgradient(cx: 0.3, cy: -0.4,
     
    fx: 0.3, fy: -0.4,
     
    radius: 1.35, stop: 0 #fff, stop: 1 #888);

    min-width: 80px;
     
    }
    change off color when hovering over the button

    PHP:

    QPushButton:hover {
    background: qradialgradient(cx: 0.3, cy: -0.4,
    fx: 0.3, fy: -0.4,
    radius: 1.35, stop: 0 #fff, stop: 1 #bbb);
    }
     
    change color when clicking button
    PHP:
    QPushButton:pressed {
     
    background: qradialgradient(cx: 0.4, cy: -0.1,
     
    fx: 0.4, fy: -0.1,
     
    radius: 1.35, stop: 0 #fff, stop: 1 #ddd);

    }
    We gonna change the background off the form
    right click anywhere on the form.
    choose changeObject name.
    paste
    Code (Text):
    TopFrame
    Right click again and choose style sheet.


    paste code

    PHP:
    #topFrame {
    border: none;
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
    stop: 0 #a6a6a6, stop: 0.08 #7f7f7f,
    stop: 0.39999 #717171, stop: 0.4 #626262,
    stop: 0.9 #4c4c4c, stop: 1 #333333);
    }
     
    #bottomFrame {
    border: none;
    background: white;
    }
    wolla

    [​IMG]

    save work as teststyle

    then do in CMD
    cd to project folder

    Code (Text):
    pyuic4 -o teststyle.py -x teststyle.ui
    then edit teststyle.py in button to make it work
    http://techbliss.org/threads/bringing-ida-pro-plugin-writing-into-2014.527/#post-1453

    here is full code and working stylesheet both in ida and windows.

    Code (Python):
    from PyQt4 import QtCore, QtGui
     
    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        def _fromUtf8(s):
            return s
     
    try:
        _encoding = QtGui.QApplication.UnicodeUTF8
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig, _encoding)
    except AttributeError:
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig)
     
    class Ui_topFrame(object):
        def setupUi(self, topFrame):
            topFrame.setObjectName(_fromUtf8("topFrame"))
            topFrame.resize(320, 240)
            topFrame.setStyleSheet(_fromUtf8("#topFrame {\n"
    "border: none;\n"
    "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\n"
    "stop: 0 #a6a6a6, stop: 0.08 #7f7f7f,\n"
    "stop: 0.39999 #717171, stop: 0.4 #626262,\n"
    "stop: 0.9 #4c4c4c, stop: 1 #333333);\n"
    "}\n"
    "\n"
    "#bottomFrame {\n"
    "border: none;\n"
    "background: white;\n"
    "}"))
            topFrame.setFrameShape(QtGui.QFrame.StyledPanel)
            topFrame.setFrameShadow(QtGui.QFrame.Raised)
            self.pushButton = QtGui.QPushButton(topFrame)
            self.pushButton.setGeometry(QtCore.QRect(40, 20, 94, 23))
            self.pushButton.setStyleSheet(_fromUtf8("QPushButton {\n"
    "color: #333;\n"
    "border: 2px solid #555;\n"
    "border-radius: 11px;\n"
    "padding: 5px;\n"
    "background: qradialgradient(cx: 0.3, cy: -0.4,\n"
    "fx: 0.3, fy: -0.4,\n"
    "radius: 1.35, stop: 0 #fff, stop: 1 #888);\n"
    "min-width: 80px;\n"
    "}\n"
    "\n"
    "QPushButton:hover {\n"
    "background: qradialgradient(cx: 0.3, cy: -0.4,\n"
    "fx: 0.3, fy: -0.4,\n"
    "radius: 1.35, stop: 0 #fff, stop: 1 #bbb);\n"
    "}\n"
    "\n"
    "QPushButton:pressed {\n"
    "background: qradialgradient(cx: 0.4, cy: -0.1,\n"
    "fx: 0.4, fy: -0.1,\n"
    "radius: 1.35, stop: 0 #fff, stop: 1 #ddd);\n"
    "}"))
            self.pushButton.setObjectName(_fromUtf8("pushButton"))
            self.pushButton_2 = QtGui.QPushButton(topFrame)
            self.pushButton_2.setGeometry(QtCore.QRect(180, 20, 94, 23))
            self.pushButton_2.setStyleSheet(_fromUtf8("QPushButton {\n"
    "color: #333;\n"
    "border: 2px solid #555;\n"
    "border-radius: 11px;\n"
    "padding: 5px;\n"
    "background: qradialgradient(cx: 0.3, cy: -0.4,\n"
    "fx: 0.3, fy: -0.4,\n"
    "radius: 1.35, stop: 0 #fff, stop: 1 #888);\n"
    "min-width: 80px;\n"
    "}\n"
    "\n"
    "QPushButton:hover {\n"
    "background: qradialgradient(cx: 0.3, cy: -0.4,\n"
    "fx: 0.3, fy: -0.4,\n"
    "radius: 1.35, stop: 0 #fff, stop: 1 #bbb);\n"
    "}\n"
    "\n"
    "QPushButton:pressed {\n"
    "background: qradialgradient(cx: 0.4, cy: -0.1,\n"
    "fx: 0.4, fy: -0.1,\n"
    "radius: 1.35, stop: 0 #fff, stop: 1 #ddd);\n"
    "}"))
            self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
     
            self.retranslateUi(topFrame)
            QtCore.QMetaObject.connectSlotsByName(topFrame)
     
        def retranslateUi(self, topFrame):
            topFrame.setWindowTitle(_translate("topFrame", "Frame", None))
            self.pushButton.setText(_translate("topFrame", "PushButton", None))
            self.pushButton_2.setText(_translate("topFrame", "PushButton", None))
     
     
    if __name__ == "__main__":
        import sys
        app = QtGui.QApplication.instance()
        if not app:
            app = QtGui.QApplication([])
        topFrame = QtGui.QFrame()
        ui = Ui_topFrame()
        ui.setupUi(topFrame)
        topFrame.show()
        app.exec_()
     
    Rip Cord likes this.
Top