def __init__(self, parent=None, width=600, hight=500, host=None, port=0, user='******', passwd=None, db=None, charset='utf8', tableName=""): super().__init__(parent) self.setWindowTitle("table") self.resize(width, hight) self.host = host self.port = port self.db = db self.user = user self.passwd = passwd self.charset = charset self.tableName = tableName mainLayout = VBoxLayout(self) self.tableWidget = DbTableWidget(host=self.host, port=self.port, user=self.user, passwd=self.passwd, db=self.db, charset=self.charset, tableName=self.tableName) mainLayout.addWidget(self.tableWidget)
class TabWidget(ScrollArea): def __init__(self, parent=None): super().__init__(parent) self.setObjectName("TransformWidget") self.tabWidget = QTabWidget() self.tabWidget.setObjectName("tabWidget") self.mainLayout = VBoxLayout() self.mainLayout.addWidget(self.tabWidget) self.frame.setLayout(self.mainLayout) self.addTabs() self.initUI() def initUI(self): """子类实现""" pass def addTabs(self): """子类实现""" pass def addTab(self, widget, *args): """ addTab(self, QWidget, str) -> int addTab(self, QWidget, QIcon, str) -> int """ self.tabWidget.addTab(widget, *args)
def __init__(self, parent=None): super().__init__(parent) self.hexIn = 10 self.hexInList = [{ 'value': 2, 'text': '2进制' }, { 'value': 8, 'text': '8进制' }, { 'value': 10, 'text': '10进制' }, { 'value': 16, 'text': '16进制' }] self.hexOutList = [{ 'value': 2, 'text': '2进制' }, { 'value': 8, 'text': '8进制' }, { 'value': 10, 'text': '10进制' }, { 'value': 16, 'text': '16进制' }] self.mainLayout = VBoxLayout(self.frame) self.mainLayout.setContentsMargins(20, 10, 0, 0) self.mainLayout.setSpacing(10) self.inRadioLayout = self.getInRadioLayout() self.mainLayout.addLayout(self.inRadioLayout) self.inputLayout = HBoxLayout() self.inputLayout.setSpacing(10) self.input = QLineEdit(self) self.input.setMinimumWidth(240) self.inputLayout.addWidget(self.input) self.transformSubmitButton = QPushButton("转换") self.inputLayout.addWidget(self.transformSubmitButton) self.inputLayout.addStretch(1) self.mainLayout.addLayout(self.inputLayout) self.resultTable = self.getResultTable() self.mainLayout.addWidget(self.resultTable) self.mainLayout.addStretch(1) self.transformSubmitButton.clicked.connect(self.transform)
def initUI(self): mainLayout = VBoxLayout(self) self.initToolBar() mainLayout.addWidget(self.toolBar) mainLayout.addWidget(HLine()) mainLayout.addWidget(self.resultText) self.resultText.setObjectName('resultText') self.resultText.setTextInteractionFlags( Qt.TextSelectableByMouse) #仅能通过鼠标选择 self.setStyleSheet(''' #resultText { border-radius: 5px; padding: 7px; color: black; background: #A5D6AD; font-size:18px; font-family: Consolas,楷体; } QToolBar{ background: #9DDBB4; border-bottom-style:1px red; } QFrame HLine{ color: #2177C7; } ''')
def __init__(self, parent=None): super().__init__(parent) self.setObjectName("TransformWidget") self.tabWidget = QTabWidget() self.tabWidget.setObjectName("tabWidget") self.mainLayout = VBoxLayout() self.mainLayout.addWidget(self.tabWidget) self.frame.setLayout(self.mainLayout) self.addTabs() self.initUI()
def __init__(self, parent=None, width=500, hight=300): super().__init__(parent) self.setWindowTitle("导出") self.resize(width, hight) self.labl1 = QLabel("文件类型:") self.fileTypeComboBox = ComboBox(datas=[{ "id": 1, "text": "csv" }, { "id": 2, "text": "excel" }], maximumWidth=200) self.labl2 = QLabel("文件保存路径:") self.pathLineEdit = FileSaveLineEdit(filter="Text files (*.csv)", maximumWidth=300) self.pathLineEdit.setPlaceholderText("输入或者选择路径") self.confirmButton = QPushButton("确定", maximumWidth=100) self.cancelButton = QPushButton("取消", maximumWidth=100) mainLayout = VBoxLayout(self, contentsMargins=(10, 10, 10, 10), spacing=10) fromlayout = QFormLayout() fromlayout.addRow(self.labl1, self.fileTypeComboBox) fromlayout.addRow(self.labl2, self.pathLineEdit) submitLayout = HBoxLayout(contentsMargins=(10, 10, 10, 10), spacing=10) submitLayout.addStretch(1) submitLayout.addWidget(self.confirmButton) submitLayout.addSpacing(20) submitLayout.addWidget(self.cancelButton) submitLayout.addStretch(1) fromlayout.setLayout(2, QFormLayout.SpanningRole, submitLayout) mainLayout.addLayout(fromlayout) self.fileTypeComboBox.currentIndexChanged.connect(self.fileTypeChanged) self.confirmButton.clicked.connect(self.accept) self.cancelButton.clicked.connect(self.reject)
def __init__(self, parent=None, host=None, port=0, user='******', passwd=None, db=None, charset='utf8', tableName="", **kwargs): super().__init__(parent, **kwargs) self.host = host self.port = port self.db = db self.user = user self.passwd = passwd self.charset = charset self.tableName = tableName mainLayout = VBoxLayout(self) self.toolBar = QToolBar() self.initToolBar() self.table = QTableWidget() self.pageTool = PageTool() mainLayout.addWidget(self.toolBar) mainLayout.addWidget(self.table) mainLayout.addWidget(self.pageTool) self.table.horizontalHeader().setStyleSheet( "QHeaderView::section{background:#F3F3F3;}") self.table.setStyleSheet("QTableWidget{border:0 none;//最外层边框}") self.table.verticalHeader().setVisible(False) # 隐藏行号 self.table.setAlternatingRowColors(True) # 隔行换色 # 设置可以自适应宽度 self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.registerSignalConnect()
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) host, port, db, user, passwd, charset = DbSetting.getDbSetting(1) self.host = host self.port = port self.db = db self.user = user self.passwd = passwd self.charset = charset self.toolBar = QToolBar() self.tablesWidget = QListWidget() self.tablesWidget.setViewMode(QListView.IconMode) self.tablesWidget.itemDoubleClicked.connect(self.tableClicked) self.initToolBar() mainLayout = VBoxLayout(self) mainLayout.addWidget(self.toolBar) mainLayout.addWidget(self.tablesWidget)
class HexConvertWidget(ScrollArea): """https://tool.lu/hexconvert""" def __init__(self, parent=None): super().__init__(parent) self.hexIn = 10 self.hexInList = [{ 'value': 2, 'text': '2进制' }, { 'value': 8, 'text': '8进制' }, { 'value': 10, 'text': '10进制' }, { 'value': 16, 'text': '16进制' }] self.hexOutList = [{ 'value': 2, 'text': '2进制' }, { 'value': 8, 'text': '8进制' }, { 'value': 10, 'text': '10进制' }, { 'value': 16, 'text': '16进制' }] self.mainLayout = VBoxLayout(self.frame) self.mainLayout.setContentsMargins(20, 10, 0, 0) self.mainLayout.setSpacing(10) self.inRadioLayout = self.getInRadioLayout() self.mainLayout.addLayout(self.inRadioLayout) self.inputLayout = HBoxLayout() self.inputLayout.setSpacing(10) self.input = QLineEdit(self) self.input.setMinimumWidth(240) self.inputLayout.addWidget(self.input) self.transformSubmitButton = QPushButton("转换") self.inputLayout.addWidget(self.transformSubmitButton) self.inputLayout.addStretch(1) self.mainLayout.addLayout(self.inputLayout) self.resultTable = self.getResultTable() self.mainLayout.addWidget(self.resultTable) self.mainLayout.addStretch(1) self.transformSubmitButton.clicked.connect(self.transform) def getInRadioLayout(self): inRadioLayout = HBoxLayout() inRadioLayout.setSpacing(10) bg1 = QButtonGroup(self) for item in self.hexInList: rb11 = QRadioButton(item['text']) bg1.addButton(rb11, item['value']) if self.hexIn == item['value']: rb11.setChecked(True) inRadioLayout.addWidget(rb11) inRadioLayout.addStretch(1) """ buttonClicked(self, QAbstractButton) [signal] buttonClicked(self, int) [signal] """ bg1.buttonClicked[int].connect(lambda x: setattr(self, 'hexIn', x)) # 也能获得选中的值 # print(bg1.checkedId()) return inRadioLayout def getResultTable(self): resultTable = QTableWidget() resultTable.setMaximumWidth(600) resultTable.setMinimumHeight(200) # resultTable.horizontalHeader().setStyleSheet("QHeaderView::section{background:#F3F3F3;}") self.setStyleSheet("QTableWidget{border:0 none;//最外层边框}") resultTable.verticalHeader().setVisible(False) # 隐藏行号 resultTable.setAlternatingRowColors(True) resultTable.setColumnCount(2) # 注意必须在初始化行列之后进行,否则,没有效果 resultTable.setHorizontalHeaderLabels(['进制', '结果']) # 设置可以自适应宽度 resultTable.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) # 设置可以自定义宽度 resultTable.horizontalHeader().setSectionResizeMode( 0, QHeaderView.Interactive) # QTableWidget的一些配置“https://blog.csdn.net/vah101/article/details/6215066” resultTable.setEditTriggers(QTableView.NoEditTriggers) # 不可编辑 resultTable.setSelectionMode(QAbstractItemView.NoSelection) # 设置不能选中 # resultTable.setSelectionBehavior(QAbstractItemView.SelectItems) # 设置只能选中单元格 # resultTable.setSelectionMode(QAbstractItemView.SingleSelection) # 设置只能选中一行 # resultTable.setSelectionBehavior(QAbstractItemView.SelectRows) # 设置只有行选中 resultTable.setColumnWidth(0, 50) # 可以设置tableview所有列的默认行高 resultTable.verticalHeader().setDefaultSectionSize(40) resultTable.setRowCount(4) for i, data in enumerate(self.hexOutList): item = QTableWidgetItem(str(data['value'])) resultTable.setItem(i, 0, item) lineEdit = QLineEdit() lineEdit.setContentsMargins(5, 5, 30, 5) lineEdit.setObjectName("rst_text_hex{}".format(data['value'])) resultTable.setCellWidget(i, 1, lineEdit) return resultTable def transform(self): hexIn = self.hexIn text = self.input.text() num = int(text, hexIn) for data in self.hexOutList: hexOut = data['value'] if hexOut == 2: rst = bin(num)[2:] elif hexOut == 8: rst = oct(num)[2:] elif hexOut == 10: rst = str(num) elif hexOut == 16: rst = hex(num)[2:] else: rst = util.hex_convert(num, hexOut) self.resultTable.findChild( QLineEdit, "rst_text_hex{}".format(hexOut)).setText(rst)