Hi,
Most of my buttons for the touchscreen are based from an example of Qt code. In the Qt package there is an example under qgraphicsview, called pad navigator. The buttons are using the object roundrectitem.cpp,h. It is a QGraphicsItem. I don't have a way to post the files here. Message me. Here is a snippet, when the button is pressed this slot is called.
{
int keyValue = count.value<int>();
// toggle the alpha characters, repaint the text inthe button
if (keyValue == Qt::Key_CapsLock)
{
m_caseToggle ^= 1;
for ( int y = 0; y < m_height; ++y)
{
for (int x = 0; x < m_width; ++x)
{
RoundRectItem *item = qgraphicsitem_cast<RoundRectItem *>(grid[y][x]);
if (m_caseToggle == true)
charString = itemValue[y][x].toLower();
else
charString = itemValue[y][x].toUpper();
if (itemValue
[y
][x
] != QChar::Null) item
->setText
(charString,
QFont(ALPHAPADFONT
),
}
}
}
QChar keyChar
= count.
toChar();
QString unicodeval
(count.
toChar());
// for alphabet encoding
// alter the keypress value for lower case
if ((keyValue <= Qt::Key_Z && keyValue >= Qt::Key_A) &&
m_caseToggle == true)
{
keyValue += 0x20; // for lower case
keyChar = keyValue;
unicodeval = keyChar;
}
if (recObject)
{
QLineEdit *lineEdit
= qobject_cast<QLineEdit
*>
(recObject
);
if(keyValue == Qt::Key_Enter)
{
unicodeval = "d";
if(lineEdit->hasAcceptableInput())
{
emit finished();
hidePad();
}
else
{
lineEdit->undo();
}
}
else if(keyValue == Qt::Key_Backspace)
unicodeval = "08";
else if(keyValue == Qt::Key_CapsLock)
return;
}
if(keyValue == Qt::Key_Enter)
hidePad();
qDebug() << "KeyPressed" << unicodeval << keyValue;
}
void AlphaPad::numEntry(QGraphicsItem *item)
{
QVariant count = item->data(QVariant::Int);
int keyValue = count.value<int>();
// toggle the alpha characters, repaint the text inthe button
if (keyValue == Qt::Key_CapsLock)
{
m_caseToggle ^= 1;
for ( int y = 0; y < m_height; ++y)
{
for (int x = 0; x < m_width; ++x)
{
RoundRectItem *item = qgraphicsitem_cast<RoundRectItem *>(grid[y][x]);
QString charString;
if (m_caseToggle == true)
charString = itemValue[y][x].toLower();
else
charString = itemValue[y][x].toUpper();
if (itemValue[y][x] != QChar::Null)
item->setText(charString,QFont(ALPHAPADFONT),
QColor(ALPHATEXTCOL),
QRectF(QPointF(ALPHATEXTRECTTL),QPointF(ALPHATEXTRECTBR)));
}
}
}
QChar keyChar = count.toChar();
QString unicodeval(count.toChar());
// for alphabet encoding
// alter the keypress value for lower case
if ((keyValue <= Qt::Key_Z && keyValue >= Qt::Key_A) &&
m_caseToggle == true)
{
keyValue += 0x20; // for lower case
keyChar = keyValue;
unicodeval = keyChar;
}
if (recObject)
{
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(recObject);
if(keyValue == Qt::Key_Enter)
{
unicodeval = "d";
if(lineEdit->hasAcceptableInput())
{
emit finished();
hidePad();
}
else
{
lineEdit->undo();
}
}
else if(keyValue == Qt::Key_Backspace)
unicodeval = "08";
else if(keyValue == Qt::Key_CapsLock)
return;
QKeyEvent keyPress(QEvent::KeyPress,keyValue,Qt::NoModifier,unicodeval);
QCoreApplication::sendEvent(recObject,&keyPress);
}
if(keyValue == Qt::Key_Enter)
hidePad();
qDebug() << "KeyPressed" << unicodeval << keyValue;
}
To copy to clipboard, switch view to plain text mode
Bookmarks