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 ...
随机推荐
- 好消息:Dubbo & Spring Boot要来了
Duboo和Spring Boot都是非常优秀的框架,现在它们要结合了.为了简化Dubbo开发集成,阿里Dubbo团队将发布基于Spring Boot的版本,可快速上手Dubbo的分布式开发,并提供了 ...
- docker删除常见命令
$ docker stop $(docker ps -a | grep "Exited" | awk '{print $1 }') //停止容器 1b7067e19d6f a840 ...
- Ubuntu18.04 安装搜狗拼音
参考文章:https://blog.csdn.net/fx_yzjy101/article/details/80243710 1. 安装fcitx sudo apt-get install fcitx ...
- vue解决sass-loader的版本过高导致的编译错误
Module build failed: TypeError: this.getResolve is not a function at Object.loader (E:\appEx\PreRese ...
- Task ProgressBar模拟现实完成后显示TextBox
private async void Form1_Load(object sender, EventArgs e) { progressBar1.Maximum = ; progressBar2.Ma ...
- 安装rubygems
转载 http://blog.csdn.net/huanghai200911/article/details/51251472 1,下载rubygems-2.4.8.tar包,下载地址:https:/ ...
- excel 导数据
参考: ="insert tsilverinfo(ss_id,memo,ss_weight,ts_id,ss_type,ModelPosX,ss_stoneW,ss_stoneWU) val ...
- centos lamp笔记
cron and crontab are missing in docker image of ubuntu 16.04 在鏡像中沒有 cron 命令 How to install php-redis ...
- [JZOJ6299] 2019.08.12【NOIP提高组A】工厂
题目 题目大意 工厂内每个人只会操作一些机器. 他们会以随机的顺序来,每次选任意一台机器来操作. 一台机器只能由一个工人来操作. 可以花费一的代价来使某个工人学会一种机器. 问花费最少的代价,使得在所 ...
- 【JZOJ6367】工厂(factory)
description 大神 wyp 开了家工厂,工厂有 n 个工人和 p 条流水线. 工厂的工人都是睡神,因此第 i 个工人只会在 si 至 ti 时刻才会工作. 每个工人都会被分派到一条流水线上, ...