PYQT Tabwidget and check box

Source: Internet
Author: User

#!/usr/bin/python

#-*-coding:utf-8-*-

From Pyqt4.qtgui import (Qapplication, Qheaderview, Qitemselectionmodel,

Qstandarditemmodel,qtableview,qcheckbox,qcombobox,

Qitemdelegate,qstyleoptionviewitem,qspinbox, Qtreeview)

From Pyqt4.qtcore import Qmodelindex, qvariant, Qt

Class Comboboxdelegate (Qitemdelegate):

def __init__ (self, Parent=none):

Super (Comboboxdelegate,self). __init__ (parent)

def createeditor (Self,parent,option,index):

Combo = Qcombobox (parent)

Combo.additems ([Unicode (Index.row ()), Unicode (Index.column ())])

return Combo

def seteditordata (self, Editor,index):

data = Index.model (). Itemfromindex (Index). Text ()

Combo_box_index = Editor.findtext (data)

Print Combo_box_index

If Combo_box_index >=0:

Editor.setcurrentindex (Combo_box_index)

def setmodeldata (self, Editor,model,index):

Text = Editor.currenttext ()

Model.setdata (index, text, qt.editrole)

Import Sys

If __name__== ' __main__ ':

App = Qapplication (SYS.ARGV)

Model=qstandarditemmodel (4, 3)

Tableview=qtableview ()

Tableview.setmodel (model)

Delegate = Comboboxdelegate ()

Tableview.setitemdelegate (delegate)

# Tableview.horizontalheader (). Setstretchlastsection (True)

For row in range (4):

For column in range (3):

index = Model.index (row, column, Qmodelindex ())

Model.setdata (Index, Qvariant ((row+1) * (column+1)))

Model.setdata (Index, Qvariant ([u ' Zã©ro ', U ' un ', u ' deux ', U ' trois '))

Tableview.setwindowtitle ("Delegate")

Tableview.show ()

APP.EXEC_ ()

PYQT Tabwidget and check box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.