hi, all
 I have test the WKeyEvent for some hotkey development on the based of
wt-2.1.4, but some unfortunate errors happened, the test case a TableView
application in a WContainerWidget, which can react to the keyPressed.

Error1: The Application can't recognize the modifiers except Shift, maybe Wt
only accept the explicitly entered character?
Error2: In this test case, the application will not get the key pressed out
the range of TableView(not including the ToolBar)

-----test case----------
#include <iostream>
#include <boost/lexical_cast.hpp>

#include <WApplication>
#include <WContainerWidget>
#include <WText>
#include <WEvent>
#include <WStandardItemModel>
#include <Ext/TableView>
#include <Ext/ToolBar>
#include <Ext/Button>

using namespace Wt;


class Test : public WApplication {

    public:

    Test(const WEnvironment& env);

    void hotKey(WKeyEvent key);

    private:

    Ext::Button *button;

};


Test::Test(const WEnvironment& env)
  : button(),
    WApplication(env) {

    WContainerWidget *ex = new WContainerWidget(root());
    ex->resize(WLength(1000), WLength(500));
    Ext::TableView *tv = new Ext::TableView(ex);
    tv->resize(WLength(1000), WLength(100));
    WStandardItemModel *model = new WStandardItemModel(2, 2, this);
    model->setHeaderData(0, boost::any(WString("test")));
    model->setHeaderData(1, boost::any(WString("test")));
    model->setData(0, 0, boost::any(WString("item")));
    model->setData(0, 1, boost::any(WString("item")));
    model->setData(1, 0, boost::any(WString("item")));
    model->setData(1, 1, boost::any(WString("item")));
    tv->setModel(model);
    tv->setTopToolBar(tv->createPagingToolBar());
    tv->topToolBar()->add(button = new Ext::Button("ok"));
    ex->keyPressed.connect(SLOT(this, Test::hotKey));
}

void Test::hotKey(WKeyEvent key) {

    button->setText("press"
            ":key()=" + WString(boost::lexical_cast<std::string>(key.key()))
+
            ";modifiers()=" +
WString(boost::lexical_cast<std::string>(key.modifiers())) +
            ";charCode()=" +
WString(boost::lexical_cast<std::string>(key.charCode())) +
            ";text()=" + WString(key.text()));
}


WApplication *createApplication(const WEnvironment& env)
{
  return new Test(env);
}

int main(int argc, char **argv)
{

  return WRun(argc, argv, &createApplication);
}
------------------------------------------------------------------------------
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to