#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:
};
#endif
#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
To copy to clipboard, switch view to plain text mode
#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;
int xpos,ypos;
};
push pushes[30];
multibuttonImpl
::multibuttonImpl( QWidget * parent, Qt
::WFlags f
) {
setMouseTracking(true);
setupUi(this);
add_item(12);
}
void multibuttonImpl::add_item(int num_of_item)
{
item_number=num_of_item;
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->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()+" ");
}
}
}
{
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));
}
}
#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));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks