Results 1 to 2 of 2

Thread: invisible region of QFrame generates mousepressevents for last child created within

  1. #1
    Join Date
    Jul 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default invisible region of QFrame generates mousepressevents for last child created within

    I've spent a couple days trying to chase down this issue and cannot seem to figure it out. My application has a frame which plays parent to a set of QPushButtons that are created during program execution in response to user input. The QPushButtons will have some additional functionality, including drag/drop capabilities so, (a) they're part of a class (called solenoid ) that is subclassed from QWidget, and (b) I've implemented mousepressevent().

    The QFrame is created using QT Designer, and I want to handle the button positioning within it myself (i.e. no layout). For now, I have a QPushButton elsewhere that creates the solenoid objects within the QFrame using the following code:



    Qt Code:
    1. void MainWindow::on_cmdMakeSols_clicked()
    2. {
    3. int i;
    4. solenoid* testSolenoid[8] = {0,0,0,0,0,0,0,0};
    5.  
    6. for(i = 0; i < 8; i++)
    7. { testSolenoid[i] = new solenoid(ui->boxSolenoidContainer, 500 + (i*30), 5, 25, 40, (i+1));
    8. testSolenoid[i]->show();
    9. }
    10.  
    11. return;
    12. }
    To copy to clipboard, switch view to plain text mode 

    And the constructor for solenoid:

    Qt Code:
    1. solenoid::solenoid(QWidget *parent, int xPos, int yPos, int width, int height, int ID_number) :
    2. QWidget(parent)
    3. {
    4. solenoidNumber = ID_number;
    5. baseXpos = xPos;
    6. baseYpos = yPos;
    7. xSize = width;
    8. ySize = height;
    9.  
    10.  
    11. clickButton.setParent(parent);
    12. clickButton.setGeometry(xPos, yPos, (width - 2), (height - 2));
    13. clickButton.show();
    14.  
    15. this->setMouseTracking(true);
    16. this->update();
    17. }
    To copy to clipboard, switch view to plain text mode 



    The problem I'm having is that there is an invisible region in the top left of the QFrame, about 130x30 pixels, which triggers the onmousepress() event for the final solenoid object created when I click within it. It sits atop any solenoid objects created in that space.

    Through experimentation, I have found that the invisible region is created when the QWidget(parent) constructor is called. Can anyone fill me in on what's going on here?! Is there a purpose for this invisible region? Is it part of the QFrame, or the object itself? Most importantly, how do I get rid of it?

    Hope my description has been clear; any guidance is much appreciated!


    EDIT: if I call testSolenoid[7].rect(); it returns a rectangle with coordinates (0,0) and (100,30), which corresponds to the "invisible spot" I'm referring to, although the widget is drawn where I expect it and responds to click events where it is drawn. I tried calling the updateGeometry() and update() methods after creating the objects, but see no change in behavior.
    Last edited by ThaChemist; 12th July 2011 at 01:31.

  2. #2
    Join Date
    Jul 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: invisible region of QFrame generates mousepressevents for last child created with

    I just figured it out! I needed to add the following call the the solenoid constructor:

    Qt Code:
    1. this->setGeometry(xPos, yPos, width, height);
    To copy to clipboard, switch view to plain text mode 

    Apparently I was moving the object's subcomponents (QPushButton + a few others), but the object itself has some physical representation as well which should be explicitly adjusted as well. Thanks to everyone who checked out this thread and though about the problem for me.

Similar Threads

  1. Replies: 5
    Last Post: 7th May 2011, 21:56
  2. Replies: 5
    Last Post: 18th April 2010, 23:31
  3. Qidget height resize if child widgets invisible
    By visor_ua in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2008, 11:27
  4. Replies: 5
    Last Post: 5th November 2007, 10:13
  5. QFrame parent, QGLWidget-based child
    By philski in forum Qt Programming
    Replies: 6
    Last Post: 28th August 2006, 18:14

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
  •  
Qt is a trademark of The Qt Company.