View Full Version : Enlarge Pushbutton?
triperzonak
20th June 2008, 06:45
hi im trying to enlarge my push button when ever the mouse points at it.
what should i do?
im trying to use "mousemoveevent" but this event happen only when the mouse was "click", i dunno y?
when you point the mouse pointer to the qpushbutton the border becomes orange and when gone back to default. i just want to do it like that, but change the size
do i need to create a custom widget for push button?
:confused:
Arghargh
20th June 2008, 06:51
Hello, you could try to enable mouse tracking for your button. It should then receive mouseMoveEvents without a clicked button.
Arghargh
triperzonak
20th June 2008, 06:58
im sorry i forgot to say that i already set the mouse tracking of all widgets to true.. my main widgets are a groupbox textedit label and button.. but mousemoveevent stiil require "click" plus a cant get the event->pos() inside my group box even i click it..
Y?
santhoshv84
20th June 2008, 07:40
Hi Friend,
Set MouseTracking to true. Then you can get the Mouse events.
Then you mouseMoveEvent(QMouseEvent *event);
So from event->pos(). you can get the current position of the mouse.
Then change the geometry of your QPushButton.
triperzonak
20th June 2008, 08:04
heres my code:
.h
#include <QMouseEvent>
#include <QMainWindow>
#include "ui_multibutton.h"
class multibuttonImpl : public QMainWindow, public Ui::multibutton
{
Q_OBJECT
public:
multibuttonImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
signals:
public slots:
void add_item();
void show_name();
protected:
void mouseMoveEvent(QMouseEvent *);
};
.cpp
multibuttonImpl::multibuttonImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setMouseTracking(true);
setupUi(this);
}
void multibuttonImpl::mouseMoveEvent(QMouseEvent *e)
{
QVariant mouse_pos=e->x();//globalPos();
textEdit->append(mouse_pos.toString());
if (pushButton->underMouse()==true )
pushButton->setGeometry(QRect(600, 210, 141, 101));
}
note: i setmousetracking=true in all my widget in my .ui but "mousemoveevent" still requires "click":confused:
note again: im using a group box
triperzonak
20th June 2008, 08:33
i think i found now the problem.. its in my group box, i try to change the groupbox into frame and now its working..
tnx.. but y is it like that?:eek:
triperzonak
20th June 2008, 09:11
weee.. i try to create dynamicaly the pushbutton and add it to frame but now its not working requires "drag click" again help...
.h
#ifndef MULTIBUTTONIMPL_H
#define MULTIBUTTONIMPL_H
//
#include <QMouseEvent>
#include <QMainWindow>
#include "ui_multibutton.h"
//
class multibuttonImpl : public QMainWindow, public Ui::multibutton
{
Q_OBJECT
public:
multibuttonImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
signals:
public slots:
void add_item(int num_of_item);
void show_name();
protected:
void mouseMoveEvent(QMouseEvent *);
};
#endif
.cpp
#include "multibuttonimpl.h"
#include "custom_button.h"
#include <QMessageBox>
#include<QVariant>
#include <QPushButton>
#include <QCoreApplication>
int item_number;
int pos_x=20,pos_y=20,max_x=300;
struct push{
int num;
QPushButton *button;
int xpos,ypos;
QString itemcode;
};
push pushes[30];
multibuttonImpl::multibuttonImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setMouseTracking(true);
setupUi(this);
add_item(12);
}
void multibuttonImpl::add_item(int num_of_item)
{
QVariant item_num;
item_number=num_of_item;
QString b;
for (int i=0;i<num_of_item;i++)
{
b="item";
item_num=i+1;
pushes[i].num=i;
b.append("_"+item_num.toString());
pushes[i].button =new QPushButton(frame);
pushes[i].button->setObjectName(b);
pushes[i].button->setCheckable(true);
pushes[i].button->setChecked(false);
pushes[i].button->setGeometry(QRect(pos_x, pos_y, 121, 81));
pushes[i].button->setText(b);
pushes[i].button->setCursor(QCursor(Qt::PointingHandCursor));
pushes[i].button->setMouseTracking(true);
//pushes[i].button->setStyleSheet("border-image: url(:/icons/itemlogo.png);");
pushes[i].xpos=pos_x;
pushes[i].ypos=pos_y;
connect (pushes[i].button, SIGNAL (clicked(bool)),this , SLOT (show_name()));
if (pos_x==max_x)
{
pos_y+=100;
pos_x=20;
}
else
pos_x+=140;
}
}
void multibuttonImpl::show_name()
{
for (int j=0;j<item_number;j++)
{
if (pushes[j].button->isChecked())
{
//pushes[j].button->setStyleSheet("");
pushes[j].button->setChecked(false);
//QMessageBox::information(this, tr("name"),pushes[j].button->objectName()+" ");
}
}
}
void multibuttonImpl::mouseMoveEvent(QMouseEvent *e)
{
for (int j=0;j<item_number;j++)
{
if (pushes[j].button->underMouse()==true)
pushes[j].button->setGeometry(QRect(pushes[j].xpos-10,pushes[j].ypos-10, 131, 91));
else
pushes[j].button->setGeometry(QRect(pushes[j].xpos, pushes[j].ypos, 121, 81));
}
}
help help help y is "mousemoveevent" not working?
triperzonak
20th June 2008, 14:58
now i found the answer on my question but created again another question..
after i remove the frame and put my dynamic buttons directly to the centralwidget like
pushbutton= new QPushButton(this)
it works!..
however y is it like that? if i put a button on a groupbox mouseevent inside it is not working.. if i put the buttons on a frame and dynamically create the buttons "mousemoveevent" is more like "mousepressevent" y?
until this time i have no problems but if i further improve my project i will have.. I cant put background image on my buttons alone cause i have no frame or groupbox it will affect the whole form.. hayyzzzzzz
note: just to clarify i setmousetracking on groupbox and frame as true, it is not the problem..
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.