Results 1 to 10 of 10

Thread: how to show fillRect() using mouseEvents??

  1. #1
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question how to show fillRect() using mouseEvents??

    hi all
    i am using QT4.1 on Mac
    i had drawn four column using QPainter class
    and drawn some text in them
    now i want to select the particular portion of text from that table just same as like QtextEdit ,in TextEditparticular selected portion get pink color,

    how the same is possible using QPainter and QMouseEvents??
    do tell me with siple code example if anyone know??

    thanks in advance....

  2. #2
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question how to show fillRect() using mouseEvents??

    hi all
    i am using QT4.1 on Mac

    i had created a table with data in diffrent columns using QPainter
    now i am selecting data from table on mousePressEvent()...and selcted upto mouseMoveEvent()...and upto that particular data i am using fillRect()...

    it is working when debugged but it is not shown on run time

    by debugging results i had seen mouseMove Event() is called again and again...so i want to know why its happening...and why its not showing painted rectangle


    if anyone know do tell me by simple example code

    i had done like this

    void MainForm::mousePressEvent ( QMouseEvent * e )
    {
    //m_DataPainter->fillRect(m_SelectedRect,Qt::white);
    m_StartingPointX= 0;
    m_StartingPointX = e->pos().x();
    m_StartingPointY= 0;
    m_StartingPointY = e->pos().y();

    }


    void MainForm::mouseMoveEvent ( QMouseEvent * e )
    {

    if (e->type() == QEvent::MouseMove)
    {
    m_EndingPointX=e->pos().x();
    m_EndingPointY=e->pos().y();
    int x2=m_EndingPointX - m_StartingPointX;
    int y2=m_EndingPointY - m_StartingPointY;
    m_DataPainter->fillRect(m_StartingPointX,m_StartingPointY,x2,y2, Qt::lightGray);
    }


    }


    thanks in advance

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to show fillRect() using mouseEvents??

    You shouldn't draw anything on your widget outside the paintEvent().

    As the docs say:
    Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.
    PS. Please, don't start more than one thread on the same topic.

  4. #4
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to show fillRect() using mouseEvents??

    You must use fillRect() in paintEvent(...) only. Do something like that:
    Qt Code:
    1. //somewhere in class
    2. bool DrawSelection;
    3.  
    4. void MainForm::paintEvent(QPaintEvent* e)
    5. {
    6. QPainter painter(this);
    7. if(DrawSelection)
    8. painter.fillRect(m_SelectedRect,Qt::white);
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 
    and in mouse press event:

    Qt Code:
    1. void MainForm::mousePressEvent (QMouseEvent * e)
    2. {
    3. ...
    4. m_StartingPointX= 0;
    5. ...
    6. //check sizes and set
    7. DrawSelection = true;
    8. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Default Re: how to show fillRect() using mouseEvents??

    thanks for reply.....
    but by doing this data get hide and color get drawn on the data

    and when i scroll down ,the painted Rectangle remain on that particular position which i had selected rather it should not to be come on ...

    and on scroll up it should be repainted how it can be done??

  6. #6
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to show fillRect() using mouseEvents??

    You need to convert pixels in line numbers (selected) in mouse move/press handlers and draw rectangle in coordinates calculated from line numbers. To make selection transparent, use QColor(255, 255, 255, 128).

  7. #7
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Default Re: how to show fillRect() using mouseEvents??

    no i dont want transparent i want to set background color
    and when i scroll down that area remain with position...but i want to change that and even for scroll up it should be repainted on that area

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to show fillRect() using mouseEvents??

    May I ask why don't you use QTextEdit?
    J-P Nurmi

  9. #9
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Default Re: how to show fillRect() using mouseEvents??

    because the requirement is not like this and on textEdit it becomes very slow when i am showing file size more thn 2Gb


    basically i dont require textEdit

    so tell me how it can be possible using QPainter

  10. #10
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to show fillRect() using mouseEvents??

    It is very simple task. You need some kind of display pointer. It may be position in source file or somethink like that. And in paintEvent you must render all data starting from this pointer. On scrolling events adjust that pointer and call update(); It is algorithm in just two words.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.