from PyQt5 import Qt
class Widget(Qt.QWidget):
def __init__(self):
super().__init__()
layout = Qt.QVBoxLayout(self)
button1 = Qt.QPushButton("Button 1")
button2 = Qt.QPushButton("Button 2")
layout.addWidget(button1)
layout.addWidget(button2)
button1.setStyleSheet("""
QPushButton {
background-color: green;
border-style: outset;
border-width: 2px;
border-radius: 10px;
border-color: beige;
font: bold 14px;
min-width: 10em;
padding: 6px;
}
QPushButton:pressed{
background-color: #4CAF50;
color: white;
border-color: black;
border-style: inset;
}
""")
if __name__ == '__main__':
app = Qt.QApplication([])
w = Widget()
w.show()
app.exec()
class ORGH_widget(Qt.QWidget):
def __init__(self, parent=None):
super(ORGH_widget, self).__init__(parent)
self.maindialog = ORGH_app(None)
self.layout = Qt.QVBoxLayout(self)
self.layout.addWidget(self.maindialog)
self.maindialog.show()
# self.exec_loop()
def keyPressEvent(self, e):
if e.key() == Qt.Qt.Key_Escape:
self.close()
class ORGH_app(Qt.QMainWindow):
def __init__(self, parent):
super(ORGH_app, self).__init__()
self.form = Ui_Form()
self.form.setupUi(self)
self._connectSlots()
def _connectSlots(self):
self.form.pushButton.clicked.connect(self._slotAddClicked)
def _slotAddClicked(self):
text = self.form.lineEdit.text()
if len(text):
# tvi = Qt.QTableViewItem(self.form.tableView)
# tvi.setText(0, text)
self.form.lineEdit.clear()
if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
main = ORGH_app(None)
main.show()
sys.exit(app.exec())
import sys
from PyQt5.Qt import QVBoxLayout, QLabel, QDialog, QDialogButtonBox, Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
class InfoDialog(QDialog):
def __init__(self, info_str, parent=None):
super(InfoDialog, self).__init__(parent)
layout = QVBoxLayout(self)
layout.addWidget(QLabel(info_str))
buttons = QDialogButtonBox(QDialogButtonBox.Ok, Qt.Horizontal, self)
buttons.accepted.connect(self.accept)
layout.addWidget(buttons)
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
exitAction = QAction(QIcon('RM.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(qApp.quit)
infoAction = QAction(QIcon(), "Info", self)
infoAction.triggered.connect(self.onInfoAction)
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(exitAction)
self.toolbar.addAction(infoAction)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Toolbar')
self.show()
def onInfoAction(self):
w = InfoDialog("Some information", self)
w.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())