在QPushButton上按Enter emits buttonClicked

时间:2018-01-26 11:59:51

标签: c++ qt qbuttongroup

我在Qt中使用C ++。我有这个问题。我有import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.RuleContext; import org.antlr.v4.runtime.tree.ParseTree; public class ASTGenerator { public static String readFile() throws IOException { File file = new File("path/to/the/test/file.java"); byte[] encoded = Files.readAllBytes(file.toPath()); return new String(encoded, Charset.forName("UTF-8")); } public static void main(String args[]) throws IOException { String inputString = readFile(); ANTLRInputStream input = new ANTLRInputStream(inputString); Java8Lexer lexer = new Java8Lexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); Java8Parser parser = new Java8Parser(tokens); ParserRuleContext ctx = parser.classDeclaration(); printAST(ctx, false, 0); } private static void printAST(RuleContext ctx, boolean verbose, int indentation) { boolean toBeIgnored = !verbose && ctx.getChildCount() == 1 && ctx.getChild(0) instanceof ParserRuleContext; if (!toBeIgnored) { String ruleName = Java8Parser.ruleNames[ctx.getRuleIndex()]; for (int i = 0; i < indentation; i++) { System.out.print(" "); } System.out.println(ruleName + " -> " + ctx.getText()); } for (int i = 0; i < ctx.getChildCount(); i++) { ParseTree element = ctx.getChild(i); if (element instanceof RuleContext) { printAST((RuleContext) element, verbose, indentation + (toBeIgnored ? 0 : 1)); } } } } (lineBox)和QLineBox(buttonGroup),其中包含QButtonGroup类型的按钮。当我在lineBox上按Enter键时,会为buttonGroup发出信号QPushButton

lineBox位于buttonClicked。此QGraphicView与buttonGroup的布局相同。按Enter键时我不想发出clickButton。任何想法为什么会这样?

我的问题和这个问题有一些区别:How to make a QPushButton pressable for enter key?。它是在autoDefault属性的初始化中。

0 个答案:

没有答案