Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Squish/Navigating a QDateEdit: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
m (style)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Tools::Squish]]
[[Category:Squish]]


= Navigating a QDateEdit =
= Navigating a QDateEdit =
Line 5: Line 5:
Interacting with a QDateEdit from a Squish script is a bit more involved than just clicking a button or writing some text into a line edit, especially if you want a nice scripting API for it as well. Below is a script function that you can cut-and-paste into your existing test case or shared script, and use without modifications. It requires you to have recorded one interaction with a QDateEdit though, to have the proper names in the object map.
Interacting with a QDateEdit from a Squish script is a bit more involved than just clicking a button or writing some text into a line edit, especially if you want a nice scripting API for it as well. Below is a script function that you can cut-and-paste into your existing test case or shared script, and use without modifications. It requires you to have recorded one interaction with a QDateEdit though, to have the proper names in the object map.


Usage would be:<br /><code>setDate(&quot;:nameOfQDateEdit&amp;quot;, &quot;2011&amp;quot;, &quot;April&amp;quot;, &quot;1&amp;quot;)<code>
Usage would be:
<code>
setDate(":nameOfQDateEdit", "2011", "April", "1")
</code>
<code>
def setDate(dateedit, year, month, day):
  waitFor("object.exists(dateedit)", 20000)
  dateExpandX = findObject(dateedit).width - 10
  sendEvent("QMouseEvent", waitForObject(dateedit), QEvent.MouseButtonPress, dateExpandX, 15, Qt.LeftButton, 0)
  sendEvent("QMouseEvent", waitForObject(dateedit), QEvent.MouseButtonRelease, dateExpandX, 15, Qt.LeftButton, 0)


</code>def setDate(dateedit, year, month, day):<br /> waitFor(&quot;object.exists(dateedit)&quot;, 20000)
  yearToolButtonName = "{name='qt_calendar_yearbutton' type='QToolButton' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  clickButton(waitForObject(yearToolButtonName))
  yearEditSpinBoxName = "{name='qt_calendar_yearedit' type='QSpinBox' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  type(waitForObject(yearEditSpinBoxName), year)
  type(waitForObject(yearEditSpinBoxName), "<Return>")


dateExpandX = findObject(dateedit).width - 10<br /> sendEvent(&quot;QMouseEvent&amp;quot;, waitForObject(dateedit), QEvent.MouseButtonPress, dateExpandX, 15, Qt.LeftButton, 0)<br /> sendEvent(&quot;QMouseEvent&amp;quot;, waitForObject(dateedit), QEvent.MouseButtonRelease, dateExpandX, 15, Qt.LeftButton, 0)
  monthToolButtonName = "{name='qt_calendar_monthbutton' type='QToolButton' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  clickButton(waitForObject(monthToolButtonName))
  monthMenuName = "{type='QMenu' unnamed='1' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  activateItem(waitForObjectItem(monthMenuName, month))


yearToolButtonName = &quot;{name='qt_calendar_yearbutton' type='QToolButton' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}&quot;<br /> clickButton(waitForObject(yearToolButtonName))
  calendarViewName = "{name='qt_calendar_calendarview' type='QCalendarView' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  waitFor("object.exists(calendarViewName)", 20000)
  model = findObject(calendarViewName).model()
  seenOne = False
  for row in range(1, model.rowCount() - 1): # First row contains day names, let's skip it
    for col in range(model.columnCount()):
      dayText = model.data(model.index(row, col)).toString()


yearEditSpinBoxName = &quot;{name='qt_calendar_yearedit' type='QSpinBox' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}&quot;<br /> type(waitForObject(yearEditSpinBoxName), year)<br /> type(waitForObject(yearEditSpinBoxName), &quot;&lt;Return&amp;gt;&quot;)
      if dayText == "1": # Some dates from last month may be seen, so make sure we've iterated
        seenOne = True # past them before we actually click an item


monthToolButtonName = &quot;{name='qt_calendar_monthbutton' type='QToolButton' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}&quot;<br /> clickButton(waitForObject(monthToolButtonName))
      if seenOne and dayText == day:
 
        waitForObjectItem(calendarViewName, "s/%s" (row, col))
monthMenuName = &quot;{type='QMenu' unnamed='1' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}&quot;<br /> activateItem(waitForObjectItem(monthMenuName, month))
        clickItem(calendarViewName, "s/%s" (row, col), 14, 11, 0, Qt.LeftButton)
 
</code>
calendarViewName = &quot;{name='qt_calendar_calendarview' type='QCalendarView' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}&quot;<br /> waitFor(&quot;object.exists(calendarViewName)&quot;, 20000)<br /> model = findObject(calendarViewName).model()<br /> seenOne = False<br /> for row in range(1, model.rowCount() - 1): # First row contains day names, let's skip it<br /> for col in range(model.columnCount()):<br /> dayText = model.data(model.index(row, col)).toString()
 
if dayText == &quot;1&amp;quot;: # Some dates from last month may be seen, so make sure we've iterated<br /> seenOne = True # past them before we actually click an item
 
if seenOne and dayText == day:<br /> waitForObjectItem(calendarViewName, &quot;s/%s&amp;quot; (row, col))<br /> clickItem(calendarViewName, &quot;s/%s&amp;quot; (row, col), 14, 11, 0, Qt.LeftButton)

Latest revision as of 10:44, 11 August 2020


Navigating a QDateEdit

Interacting with a QDateEdit from a Squish script is a bit more involved than just clicking a button or writing some text into a line edit, especially if you want a nice scripting API for it as well. Below is a script function that you can cut-and-paste into your existing test case or shared script, and use without modifications. It requires you to have recorded one interaction with a QDateEdit though, to have the proper names in the object map.

Usage would be:

setDate(":nameOfQDateEdit", "2011", "April", "1")
def setDate(dateedit, year, month, day):
  waitFor("object.exists(dateedit)", 20000)
  dateExpandX = findObject(dateedit).width - 10
  sendEvent("QMouseEvent", waitForObject(dateedit), QEvent.MouseButtonPress, dateExpandX, 15, Qt.LeftButton, 0)
  sendEvent("QMouseEvent", waitForObject(dateedit), QEvent.MouseButtonRelease, dateExpandX, 15, Qt.LeftButton, 0)

  yearToolButtonName = "{name='qt_calendar_yearbutton' type='QToolButton' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  clickButton(waitForObject(yearToolButtonName))
  yearEditSpinBoxName = "{name='qt_calendar_yearedit' type='QSpinBox' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  type(waitForObject(yearEditSpinBoxName), year)
  type(waitForObject(yearEditSpinBoxName), "<Return>")

  monthToolButtonName = "{name='qt_calendar_monthbutton' type='QToolButton' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  clickButton(waitForObject(monthToolButtonName))
  monthMenuName = "{type='QMenu' unnamed='1' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  activateItem(waitForObjectItem(monthMenuName, month))

  calendarViewName = "{name='qt_calendar_calendarview' type='QCalendarView' visible='1' window=':qt_datetimedit_calendar_QCalendarPopup'}"
  waitFor("object.exists(calendarViewName)", 20000)
  model = findObject(calendarViewName).model()
  seenOne = False
  for row in range(1, model.rowCount() - 1): # First row contains day names, let's skip it
    for col in range(model.columnCount()):
      dayText = model.data(model.index(row, col)).toString()

      if dayText == "1": # Some dates from last month may be seen, so make sure we've iterated
        seenOne = True # past them before we actually click an item

      if seenOne and dayText == day:
        waitForObjectItem(calendarViewName, "s/%s" (row, col))
        clickItem(calendarViewName, "s/%s" (row, col), 14, 11, 0, Qt.LeftButton)