Unsuccessfully post Event



  • Hi guys,

    I wanna post a QWheelEvent to QPlaintextEditor which is in a QVBoxLayout, but it does not work, I can not get that event. Welcome any ideas

    @ShowD::ShowD( QWidget *parent )
    : QDialog( parent )
    {
    // Disables the "?" What's This button from the dialog.
    setWindowFlags( Qt::Dialog | Qt::WindowTitleHint );

    setFocusPolicy( Qt::StrongFocus );

    // this dialog is built from code (no FORM [*.ui] file).
    resize( 700, 600 );

    setWindowTitle( tr( "Legal" ) );

    myVerticalLayout = new QVBoxLayout( this );
    myVerticalLayout->setContentsMargins( 6, 6, 6, 6 );

    myTextEdit = new QPlainTextEdit( this );

    // set editor to read-only (no editing allowed)
    myTextEdit->setReadOnly( true );
    myTextEdit->setEnabled( true );

    // add the text edit to the layout
    myVerticalLayout->addWidget( myTextEdit );
    }@

    @ QPoint pos = QPoint( 10, 10 );
    QApplication::postEvent( myTextEdit, new QWheelEvent( pos, 120, Qt::NoButton, Qt::NoModifier ) );
    @



  • Install event filter for myTextEdit, no need to post events. Read more on "QObject::installEventFilter":http://qt-project.org/doc/QObject.html#installEventFilter



  • thank you for advice, If I wanna postEvent, How should I do?



  • Sorry it seems I misunderstood your question. If you want to control the scroll bar position you can just do this:
    @QScrollBar *tQScrollBar = myTextEdit->verticalScrollBar();
    tQScrollBar->setValue(120);@

    Or maybe your intention is something else..



  • thanks. but my basic idea is to simulate a wheel Event as soon as something happen. post QWheelEvent is one of my choose. I have no idea what is wrong with my code above? welcome any other talent.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.