PDA

View Full Version : Qpushbutton mouse click not working with GUI



udit
14th August 2009, 16:10
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

Chisum
14th August 2009, 16:24
You really need to show some code for this problem. Better yet, a short simple program that demonstrates the problem.

Gary

udit
14th August 2009, 18:54
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,

wagmare
15th August 2009, 07:14
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 ..

udit
15th August 2009, 13:16
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

tommy
16th August 2009, 18:16
In your main.cpp have something like this:


MyWidget::MyWidget(QWidget* parent): QWidget(parent)
{
//make layouts and buttons
mainLayout = new QVBoxLayout;
statusLayout = new QHBoxLayout;
myButton = new QPushButton("Button");

//connect button and function
connect(myButton, SIGNAL(clicked()), this, SLOT(myFunction()));

//set layouts and buttons
mainLayout->addLayout(buttonLayout);
buttonLayout->addWidget(myButton);
setLayout(mainLayout);
}


Then you would call this from your main function:


int main(int argc, char *argv[])
{
QApplication application(argc, argv);

MyWidget window;
window.show();
return application.exec();
}


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



class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget (QWidget* parent = 0);

public slots:
void myFunction(void);

private:
QVBoxLayout* mainLayout;
QHBoxLayout* buttonLayout;
QPushButton* myButton;
}


Hope that helped a bit.

jibolso
25th August 2009, 01:01
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?

franz
26th August 2009, 07:21
You can develop the GUI without coding, but you can't develop the functionality without writing code.