File: test_qabstractitemview.py

package info (click to toggle)
python-anyqt 0.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: python: 4,087; makefile: 192; sh: 3
file content (46 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import  unittest
import warnings

from AnyQt.QtCore import QStringListModel
from AnyQt.QtWidgets import QApplication, QTableView, QStyledItemDelegate, \
    QStyleOptionViewItem


class Test_QAbstractItemView_itemDelegate(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        super().setUpClass()
        app = QApplication.instance()
        if app is None:
            app = QApplication([])
        cls.app = app

    @classmethod
    def tearDownClass(cls) -> None:
        cls.app = None
        super().tearDownClass()

    def test_qabstratitemview_item_delegate_for_index(self):
        view = QTableView()
        model = QStringListModel()
        model.setStringList(["AA", "BB"])
        view.setModel(model)
        idx1 = model.index(0, 0)
        idx2 = model.index(1, 0)
        delegate = QStyledItemDelegate()
        view.setItemDelegate(delegate)
        with warnings.catch_warnings(record=True):
            self.assertIs(view.itemDelegate(idx1), delegate)
            self.assertIs(view.itemDelegate(idx2), delegate)

    def test_qabstractitemview_view_options(self):
        view = QTableView()
        with warnings.catch_warnings(record=True):
            opt1 = view.viewOptions()
        self.assertIs(opt1.widget, view)
        self.assertTrue(opt1.showDecorationSelected)
        opt2 = QStyleOptionViewItem()
        view.initViewItemOption(opt2)
        self.assertIs(opt2.widget, view)
        self.assertTrue(opt2.showDecorationSelected)