pyQT Dialog默认选中某一个选项问题的解决
方法一:
在新建ui文件时不要新建Dialog

# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'D:\pythonProjects\pyqtUITest\untitled6.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import * class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(188, 250)
self.exit_game = QtWidgets.QPushButton(Form)
self.exit_game.setGeometry(QtCore.QRect(0, 200, 189, 51))
self.exit_game.setObjectName("exit_game")
self.new_game = QtWidgets.QPushButton(Form)
self.new_game.setGeometry(QtCore.QRect(0, 50, 189, 51))
self.new_game.setObjectName("new_game")
self.return_to_mainMenu = QtWidgets.QPushButton(Form)
self.return_to_mainMenu.setGeometry(QtCore.QRect(0, 150, 189, 51))
self.return_to_mainMenu.setObjectName("return_to_mainMenu")
self.continue_button = QtWidgets.QPushButton(Form)
self.continue_button.setGeometry(QtCore.QRect(0, 0, 189, 51))
self.continue_button.setObjectName("continue_button")
self.ranking_list = QtWidgets.QPushButton(Form)
self.ranking_list.setGeometry(QtCore.QRect(0, 100, 189, 51))
self.ranking_list.setObjectName("ranking_list") Form.setWindowFlags(Qt.FramelessWindowHint) self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.exit_game.setText(_translate("Form", "退出游戏"))
self.new_game.setText(_translate("Form", "新游戏"))
self.return_to_mainMenu.setText(_translate("Form", "返回主菜单"))
self.continue_button.setText(_translate("Form", "继续游戏"))
self.ranking_list.setText(_translate("Form", "排行榜")) if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
方法二:在建的Dialog模板中传入MainWindow的参数
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'Sub_menu.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets
# from PyQt5.QtCore import *
# from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(189, 250)
# self.setWindowFlags(Qt.FramelessWindowHint)
# self.setWindowFlags(Qt.FramelessWindowHint)
self.pushButton_3 = QtWidgets.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(0, 0, 189, 51))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_4 = QtWidgets.QPushButton(Dialog)
self.pushButton_4.setGeometry(QtCore.QRect(0, 50, 189, 51))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_6 = QtWidgets.QPushButton(Dialog)
self.pushButton_6.setGeometry(QtCore.QRect(0, 100, 189, 51))
self.pushButton_6.setObjectName("pushButton_6")
self.pushButton_7 = QtWidgets.QPushButton(Dialog)
self.pushButton_7.setGeometry(QtCore.QRect(0, 150, 189, 51))
self.pushButton_7.setObjectName("pushButton_7")
self.pushButton_8 = QtWidgets.QPushButton(Dialog)
self.pushButton_8.setGeometry(QtCore.QRect(0, 200, 189, 51))
self.pushButton_8.setObjectName("pushButton_8") Dialog.setWindowFlags(Qt.FramelessWindowHint)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton_3.setText(_translate("Dialog", "继续游戏"))
self.pushButton_4.setText(_translate("Dialog", "新游戏"))
self.pushButton_6.setText(_translate("Dialog", "排行榜"))
self.pushButton_7.setText(_translate("Dialog", "返回主菜单"))
self.pushButton_8.setText(_translate("Dialog", "退出游戏")) if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_Dialog()
ui.setupUi(MainWindow) #这里传入了一个MainWindow的参数
MainWindow.show()
sys.exit(app.exec_())
这里我喜欢使用第一种方法解决Dialog界面会默认选中一个选项的问题。
pyQT Dialog默认选中某一个选项问题的解决的更多相关文章
- easyui的combobox默认选中第一个选项
pmProjectSelect.combobox({ editable:false, width:165, url : ctx + '/PmProject/findByProjectMgr', //c ...
- vue select二级城市联动及第二级默认选中第一个option值
当二级联动比如选择国家的时候,希望选中一个国家的时候后面城市默认选中第一个城市,则给国家的select加一个@change事件就可以了 <div class="inputLine&qu ...
- thymeleaf单选回显,多选回显,选回显,下拉默认选中第一个
//默认选中第一个<input type ="radio" name="repaymentType" th:each ="repaymentTy ...
- Java easyui 下拉框默认选中第一个
html代码: <tr> <td> <div style="margin-bottom:5px">计价方式: <%--下拉框默认选中第 ...
- 对于for循环构成的九宫格里的button,如何满足“有默认选中的一个,并且只能选中一个”?
需要构造一个全局变量self.priceBtn 在九宫格写法中 ) { self.priceBtn = btn; self.priceBtn.selected = YES; } 在button的点击方 ...
- VUE 单选下拉框Select中动态加载 默认选中第一个
<lable>分类情况</lable> <select v-model="content.tid"> <option v-for=&quo ...
- gallery 从最左边开始显示并且默认选中第一个
import android.content.Context; import android.graphics.Camera; import android.graphics.Matrix; impo ...
- jQuery设置下拉框select 默认选中第一个option
$("#id option:first").prop("selected", 'selected');
- jquery 纯JS设置select下拉框,并默认选中第一个
//html页面<select id="payWay" class="easyui-combobox" name="payWay" s ...
随机推荐
- XStream入门应用程序
在进入XStream库的细节之前,让我们来看看应用程序操作.在这个例子中,我们创建Student和Address类.还将创建一个Student对象,然后将其序列化到一个XML字符串.然后反序列化的同一 ...
- Springboot-WebSocket获取HttpSession问题
换了新工作,第一个任务就是和这个有关,以前没接触过,没办法,各种度娘.谷哥,大部分都是只言片语,要么就是特定的配置环境还不贴配置--,踩坑无数, 遂整理成笔记 WebSocket协议 WebSocke ...
- POJ 1946 Cow Cycling
Cow Cycling Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2516 Accepted: 1396 Descr ...
- Python编程从入门到实践
Python编程从入门到实践1 起步2 变量和简单数据类型3 列表简介4 操作列表5 if语句6 字典7 用户输入和while循环8 函数9 类10 文件和异常11 测试代码12 武装飞船13 外星人 ...
- Ajax加载数据的使用
需求就是不能再进入页面时加载数据,只能在点击其中一个按钮时把数据加载呈现出来.具体效果如最下面的图. 1.前台页面 <h1 " onclick="GetData(1)&quo ...
- vue 兄弟组件的传值
handleLetterClick方法,采用emit 传递给父组件 父组件触发的方法: handleLetterChange方法: 父组件传递给子组件: CityList组件: 兄弟组件的传值可以 ...
- CSIC_716_20191106【列表、元组、字典、集合】
python的数据类型及其内置方法 一.列表(续) list.count( ).list.index( ) list = ['1', '2', '3', '2', 'a', 'b', 'c', 'a' ...
- Python 输入字符串找(String)下标 没有返回-1
str = "abcdefg123456"a = input("请输入一个字母或数字:")num = 0result = -1while num < le ...
- Idea jsp页面乱码
jsp页面中添加 <%@ page language="java" contentType="text/html; charset=utf-8" page ...
- 共享商业&技术红利,阿里云SaaS加速器让天下没有难做的SaaS
9月26日,阿里云在2019杭州云栖大会上发布了SaaS加速器3.0版“一云多端”多个应用平台,展示了阿里云给伙伴带来的多种商业和技术红利.阿里云SaaS加速器将帮助伙伴做好SaaS,卖好SaaS:帮 ...