Results 1 to 8 of 8

Thread: Qpushbutton mouse click not working with GUI

  1. #1
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Qpushbutton mouse click not working with GUI

    I have Widnows Vista installed on my system and recently installed QT 4.5.2 ON my system

    I am totally a newbie and was running some examples when i found out that whenever I run apps with QpushButton added using Qdeveloper by dragging and ddropping
    it doesnt work

    I add slot to it but on running app, clicking on the Push button doesnt work, though pressing the enter button does the job but no Mouse press works. Pls help and telll where i am lagging

    The examples that i used which involved declaring and then connecting via connect worked fine but where am i going wrong graphically

    please help
    thanks in advance

  2. #2
    Join Date
    Mar 2009
    Location
    California, USA
    Posts
    31
    Thanks
    2
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton mouse click not working with GUI

    You really need to show some code for this problem. Better yet, a short simple program that demonstrates the problem.

    Gary

  3. #3
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qpushbutton mouse click not working with GUI

    i just used qtcreator
    dragged and dropped a qpush button
    then pressed f4 entered signal slot editor

    there i connected pushbutton clicked() [not clicked(bool)]with Dialog's accept()

    thats the reason when i press enter the dialog closes but that doesnt explain why mouse click on push button does not work ?

    i didnt do any coding,
    Last edited by udit; 14th August 2009 at 19:01. Reason: updated contents

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton mouse click not working with GUI

    when i press enter the dialog closes but that doesnt explain why mouse click on push button does not work ?
    because QPushButton have the current focus which will have both keyPressEvent() and mouseClickEvent() ... when u press enter it call signal clicked() of QPushButton ..

    u have to reject() the keyPressEvent() on QPushButton or change the focus from QPushButton .. it will work ..
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Qpushbutton mouse click not working with GUI

    Quote Originally Posted by wagmare View Post
    because QPushButton have the current focus which will have both keyPressEvent() and mouseClickEvent() ... when u press enter it call signal clicked() of QPushButton ..

    u have to reject() the keyPressEvent() on QPushButton or change the focus from QPushButton .. it will work ..

    thanks wagmare, that explains a little but i found the real problem
    It was layout
    I just placed the buttons
    and then on top of that i placed the layoit due to which the buttons being below it(the layout overlapping the button)

    it never get clicked

    Second when i add buttons over the layout the problems come that they take whole of the layout

    so can anyone explicitly guiide me how to use layouts cause thats the main reason for me going wrong

    When i added buttons on the layout, it worked perfectly fine

    Hope to hear from you and sure to join your community

  6. #6
    Join Date
    Nov 2007
    Posts
    103
    Thanks
    71
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qpushbutton mouse click not working with GUI

    In your main.cpp have something like this:
    Qt Code:
    1. MyWidget::MyWidget(QWidget* parent): QWidget(parent)
    2. {
    3. //make layouts and buttons
    4. mainLayout = new QVBoxLayout;
    5. statusLayout = new QHBoxLayout;
    6. myButton = new QPushButton("Button");
    7.  
    8. //connect button and function
    9. connect(myButton, SIGNAL(clicked()), this, SLOT(myFunction()));
    10.  
    11. //set layouts and buttons
    12. mainLayout->addLayout(buttonLayout);
    13. buttonLayout->addWidget(myButton);
    14. setLayout(mainLayout);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Then you would call this from your main function:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication application(argc, argv);
    4.  
    5. MyWidget window;
    6. window.show();
    7. return application.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Of course your *.h file will need to declare the buttons and layouts accordingly. Like this:

    Qt Code:
    1. class MyWidget : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. MyWidget (QWidget* parent = 0);
    6.  
    7. public slots:
    8. void myFunction(void);
    9.  
    10. private:
    11. QVBoxLayout* mainLayout;
    12. QHBoxLayout* buttonLayout;
    13. QPushButton* myButton;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Hope that helped a bit.
    Last edited by tommy; 16th August 2009 at 18:26.
    Use computer programming to do science!
    www.scienceprogramming.com

  7. #7
    Join Date
    Aug 2009
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton mouse click not working with GUI

    Am glad there's a forum like this...uhmmm am trying to build a GUI application with QT designer and i have various form( main windows & dialog) but my major problem is connecting objects in a form to object in another form...for instance clicking a pushbutton on the main wondow and have it open a dialog.......can i develop a gui, totally using Qt designer without writing codes?

  8. #8
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton mouse click not working with GUI

    You can develop the GUI without coding, but you can't develop the functionality without writing code.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Replies: 1
    Last Post: 10th July 2009, 09:54
  2. Word at mouse click position in QGraphicsTextItem
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 04:56
  3. Replies: 11
    Last Post: 15th July 2008, 13:11
  4. QGraphicItem mouse click detection
    By PrimeCP in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 11:35

Tags for this Thread

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.