当前位置:编程学习 > 网站相关 >>

PyQt学习总结

1)QDoubleSpinBox()
setRange(min,max)       设置范围Min~max
setSingleStep(step)     设置步长为step
setValue(value)         设置当前值为value
setPrefix("$")          设置前缀为$
setSuffix("%")         设置后缀为%
selectAll()             当前值被选中
2)connect
self.connect(w, SIGNAL("signalSignature"), functionName)
self.connect(w, SIGNAL("signalSignature"), instance.methodName)
selfs.connect(w, SIGNAL("signalSignature"), instance, SLOT("slotSignature"))
w发送信号signalSignature,instance执行slotSignature动作。
3)QGridLayout
i)addWidget(w, r, c): 在r行c列添加一个固件w;
ii)addWidget(w, r, c, l, h): 在r行c列添加一个固件w,而且长l宽h;
iii)addLayout(l, r, c): 在r行c列添加一个布局;相同的,添加多两个参数之后与上面的类似;
QHBoxLayout(水平布局)和QVBoxLayout(垂直布局)
4)QListWidget   www.zzzyk.com
addItem(QString): 添加一项;
addItems(list): 添加多项;
count(): 字符串数;
takeItem(r): 删除第r项,r从0开始;
item(r): 第r项,返回的是QListWidgetItem类型, 而且可以修改值;
item(r).text(): 返回第r项的QString值;
item(r).setText(QString): 修改第r项的值;
currentItem(): 当前项,同样返回的是QListWidgetItem类型;
currentRow(): 返回当前行(int), 即第几项。
5)QMessageBox
QMessageBox类成员:
enum Icon { NoIcon = 0, Information = 1, Warning = 2, Critical = 3 }
QMessageBox ( QWidget * parent = 0, const char * name = 0 )
QMessageBox ( const QString & caption, const QString & text, Icon icon, int button0, int button1, int button2, QWidget * parent = 0, const char * name = 0, bool modal = TRUE, WFlags f = WStyle_DialogBorder )
~QMessageBox ()
QString text () const
void setText ( const QString & )
Icon icon () const
void setIcon ( Icon )const 
QPixmap * iconPixmap () const
void setIconPixmap ( const QPixmap & )
QString buttonText ( int button ) const
void setButtonText ( int button, const QString & text )
virtual void adjustSize ()TextFormat textFormat () const
void setTextFormat ( TextFormat )
静态公有成员
int information ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1 = 0, int button2 = 0 )
int information ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )
int warning ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 )
int warning ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )
int critical ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 )
int critical ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )
void about ( QWidget * parent, const QString & caption, const QString & text )void aboutQt ( QWidget * parent, const QString & caption = QString::null )
int message ( const QString & caption, const QString & text, const QString & buttonText = QString::null, QWidget * parent = 0, const char * = 0 )  (obsolete)
bool query ( const QString & caption, const QString & text, const QString & yesButtonText = QString::null, const QString & noButtonText = QString::null, QWidget * parent = 0, const char * = 0 )  (obsolete)
QPixmap standardIcon ( Icon icon, GUIStyle style )  (obsolete)
QPixmap standardIcon ( Icon icon )
属性
Icon icon - 消息框的图标
QPixmap iconPixmap - 当前图标
QString text - 被显示的消息框文本
TextFormat textFormat - 消息框中被显示的文本的格式
在PyQt中的应用
QMessageBox.information(self,"Information",self.tr("填写任意想告诉于用户的信息!"))
warningRe=QMessageBox.warning(self,"Warning",
                                self.tr("是否保存对文档的修改?"),
                                QMessageBox.Save|QMessageBox.Discard|QMessageBox.Cancel,
                                QMessageBox.Save)
if warningRe == QMessageBox.Save
QMessageBox.critical(self,"Critical",
                             self.tr("提醒用户一个致命的错误!"))
                             
QMessageBox.aboutQt(self,"About Qt")
自定义消息框
customMsgBox=QMessageBox(self)
customMsgBox.setWindowTitle("Custom message box")
lockButton=customMsgBox.addButton(self.tr("锁定"),QMessageBox.ActionRole)
unlockButton=customMsgBox.addButton(self.tr("解锁"),QMessageBox.ActionRole)
cancelButton=customMsgBox.addButton("取消",QMessageBox.ActionRole)
customMsgBox.setText(self.tr("这是一个自定义消息框!"))
customMsgBox.exec_()
button=customMsgBox.clickedButton()
if button==lockButton:
 
 
 
补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,