Results 1 to 5 of 5

Thread: Setting areas of MainWindow that are click responsive

  1. #1
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Setting areas of MainWindow that are click responsive

    I am working on a tic tac toe program. At the moment, I am trying to make it so that you can click where you want the "x" to go. I currently have an event handler for a mouse click:
    Qt Code:
    1. void QWidget::mousePressEvent ( QMouseEvent *event )
    2. {
    3. QPoint mousePos = mapFromGlobal(QCursor::pos());
    4. }
    To copy to clipboard, switch view to plain text mode 

    My goal now is to set up 9 different areas in the main window. I then want to determine which area received the click. What would these functions look like?
    The 9 areas would fall in between the squares of the tic tac toe board. The function that draws that is here:

    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter painter(this);
    4.  
    5. // Draw Tic Tac Toe Board
    6. painter.setRenderHint(QPainter::Antialiasing, true);
    7. painter.setPen(QPen(Qt::black, 10, Qt::SolidLine, Qt::RoundCap,
    8. Qt::MiterJoin));
    9. painter.drawLine(80, 20, 80, 250);
    10.  
    11. painter.setRenderHint(QPainter::Antialiasing, true);
    12. painter.setPen(QPen(Qt::black, 10, Qt::SolidLine, Qt::RoundCap,
    13. Qt::MiterJoin));
    14. painter.drawLine(170, 20, 170, 250);
    15.  
    16. painter.setRenderHint(QPainter::Antialiasing, true);
    17. painter.setPen(QPen(Qt::black, 10, Qt::SolidLine, Qt::RoundCap,
    18. Qt::MiterJoin));
    19. painter.drawLine(10, 90, 250, 90);
    20.  
    21. painter.setRenderHint(QPainter::Antialiasing, true);
    22. painter.setPen(QPen(Qt::black, 10, Qt::SolidLine, Qt::RoundCap,
    23. Qt::MiterJoin));
    24. painter.drawLine(10, 180, 250, 180);
    25. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting areas of MainWindow that are click responsive

    There is a tic tac toe implementation available in Qt docs. Have a look at it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Setting areas of MainWindow that are click responsive

    Thanks, but is there a way to do it without Qt Quick?
    Edit: And I don't want the "x"s and "o"s to be buttons. I have the code to draw them done already. I just need code to draw them where the click happens.
    Last edited by yonibr; 1st April 2012 at 15:25.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting areas of MainWindow that are click responsive

    The example I mean is not using Qt Quick.

    Task Menu Extension
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    yonibr (1st April 2012)

  6. #5
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Setting areas of MainWindow that are click responsive

    can you post the link?

    oops, just realized you did, sorry

Similar Threads

  1. Replies: 0
    Last Post: 15th December 2011, 10:26
  2. QDialog problem when setting mainwindow as parent
    By superpacko in forum Qt Programming
    Replies: 3
    Last Post: 21st July 2011, 09:35
  3. Keeping your application responsive
    By chezifresh in forum Qt Programming
    Replies: 6
    Last Post: 30th March 2011, 01:45
  4. Replies: 2
    Last Post: 5th March 2009, 10:34
  5. How to keep the GUI responsive?
    By drjones in forum Qt Programming
    Replies: 8
    Last Post: 16th July 2008, 14:33

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.