我有一个QGraphicsTextItem表现为lineedit,使用
setTextInteractionFlags(Qt::TextEditorInteraction);
但是,如果用户按下输入,它将显示多行。我希望它忽略换行,怎么做?
答案 0 :(得分:3)
AFAIK QGraphicsTextItem没有实现该功能。您可以通过继承QGraphicsTextItem并过滤键盘事件来实现这一目的:
App.controller('InviteController', function ($scope, $rootScope, $routeParams, $location, UserServices) {
$scope.init = function () {
console.log("hii this is a test ")
};
$scope.email = {};
$scope.AddToInviteList = function () {
UserServices.AddToInviteList($scope.email, function (dataresponse) {
console.log(dataresponse);
})
}
答案 1 :(得分:2)
我最终使用以下代码。和@wasthishelpful一样的想法。
class GraphicsLineEditItem : public QGraphicsTextItem {
Q_OBJECT
public:
explicit GraphicsLineEditItem(QGraphicsItem *parent = 0) : QGraphicsTextItem(parent)
{ setTextInteractionFlags(Qt::TextEditorInteraction); }
signals:
void returnPressed();
protected:
void keyPressEvent(QKeyEvent *event) {
switch (event->key()) {
case Qt::Key_Return:
case Qt::Key_Enter:
emit returnPressed();
break;
default:
QGraphicsTextItem::keyPressEvent(event);
}
}
};