I want to make a program that shows the info of a QGraphicsItem (width and height) by clicking the option "info" inside a context menu I created with the QGraphicsSceneContextMenuEvent. Right now I´m just trying to call a function with a qDebug in it called info.
Here's my code
dialog.h:
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include "QtCore"
#include "QtGui"
#include "mysquare.h"
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
private:
Ui::Dialog *ui;
QGraphicsScene *scene;
MySquare *square;
};
#endif // DIALOG_H
dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
#include <QWidget>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
square=new MySquare();
scene->addItem(square);
}
Dialog::~Dialog()
{
delete ui;
}
mysquare.h
#ifndef MYSQUARE_H
#define MYSQUARE_H
#include <QPainter>
#include <QGraphicsItem>
#include <QDebug>
#include <QMenu>
class MySquare: public QGraphicsItem
{
public:
MySquare();
QRectF boundingRect() const;
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QMenu *menu;
QAction *heightAct;
QAction *widthAct;
QAction *color;
private slots:
void info();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
};
#endif // MYSQUARE_H
mysquare.cpp
#include "mysquare.h"
#include<QMenu>
#include <string>
using namespace std;
MySquare::MySquare()
{
}
QRectF MySquare::boundingRect() const
{
return QRectF(100,100,50,50);
}
void MySquare::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF rec = boundingRect();
QBrush brushy(Qt::green);
painter->fillRect(rec,brushy);
painter->drawRect(rec);
}
void MySquare::info()
{
qDebug()<<"HERE'S MY INFO!!!";
}
void MySquare::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QString height = "Height: "+QString::number(boundingRect().height());
QString width = "Width: "+QString::number(boundingRect().width());
menu = new QMenu();
heightAct = menu->addAction(height);
widthAct = menu->addAction(width);
color = menu->addAction("Change color");
menu->exec(QCursor::pos());
}
To make a "link" between a click on an action in your menu and your slot info(), you need to use the signal/slot mechanism.
You only have to add a QObject::connect(...) in your QMenu initialization.
void MySquare::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QString height = "Height: "+QString::number(boundingRect().height());
QString width = "Width: "+QString::number(boundingRect().width());
menu = new QMenu();
heightAct = menu->addAction(height);
widthAct = menu->addAction(width);
color = menu->addAction("Change color");
QObject::connect(heightAct, SIGNAL(triggered()), this, SLOT(info()));
menu->exec(QCursor::pos());
}
However, the above code will not compile because signal/slot mechanism work only with subclasses of QObject and QGraphicsItem isn't. So you have to change it to a QGraphicsObject. (Don't forget the Q_OBJECT macro though)
Also, a little out of subject:
Use
#include <QtCore>
instead of
#include "QtCore"
but I really advise you to just include what you need, not the whole QtCore library.
Also, put your includes in your source files instead of your header files except when it's impossible.
Don't mix standard C++ library such as
#include <string>
except when it's absolutely needed. In this case you have to include
#include <QString>
And just simply remove
using namespace std;
Related
I have my MainWindow with a GraphicsView on which I want to draw a QRubberBand using MouseEvents. Therefore I created a custom GraphicsView class where I have the MouseEvents, however since I am a beginner, I don't know how to connect everything to the MainWindow.
Here's what I got so far:
mousegraphics.h (custom)
#ifndef MOUSEGRAPHICS_H
#define MOUSEGRAPHICS_H
#include <QGraphicsView>
#include <QWidget>
#include <QMainWindow>
#include <QRubberBand>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QMouseEvent>
#include <QEvent>
class MouseGraphics : public QGraphicsView
{
public:
MouseGraphics(QWidget* parent = nullptr);
public slots:
void mousePressEvent(QMouseEvent* e);
void mouseMoveEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent* e);
private:
QRubberBand* rb = nullptr;
// Coordinates
QPoint origin, dest;
};
#endif // MOUSEGRAPHICS_H
mousegraphics.cpp
#include "mousegraphics.h"
MouseGraphics::MouseGraphics(QWidget* parent) : QGraphicsView(parent)
{
}
void MouseGraphics::mousePressEvent(QMouseEvent *e)
{
origin = e->pos();
if(!rb)
{
rb = new QRubberBand(QRubberBand::Line, this);
}
rb->setGeometry(QRect(origin, QSize()));
rb->show();
}
void MouseGraphics::mouseMoveEvent(QMouseEvent *e)
{
rb->setGeometry(QRect(origin, e->pos()).normalized());
}
void MouseGraphics::mouseReleaseEvent(QMouseEvent *e)
{
rb->hide();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QRubberBand>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QMouseEvent>
#include <QEvent>
#include "mousegraphics.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
public slots:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
you should create one class that inherits from QGraphicsView.
because you need mousePressEvent ,mouseReleaseEvent , mouseMoveEvent of QGraphicsView.
Then in MainWindow, you need one QGraphicsScene object and I create one QGridLayout and with the addWidget function add my QGraphicsView object to MainWindow UI.
So I do this :
In graphicsview.h:
#ifndef GRAPHICSVIEW_H
#define GRAPHICSVIEW_H
#include <QGraphicsView>
#include <QObject>
#include <QRubberBand>
class graphicsView: public QGraphicsView
{
public:
graphicsView();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
QRubberBand *rubberBand = nullptr;
QPoint origin;
};
#endif // GRAPHICSVIEW_H
graphicsview.cpp :
#include "graphicsview.h"
#include <QMouseEvent>
#include <QRect>
graphicsView::graphicsView()
{
}
void graphicsView::mousePressEvent(QMouseEvent *event)
{
origin = event->pos();
if (!rubberBand)
{
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
}
rubberBand->setGeometry(QRect(origin, QSize()));
rubberBand->show();
}
void graphicsView::mouseReleaseEvent(QMouseEvent *event)
{
rubberBand->hide();
}
void graphicsView::mouseMoveEvent(QMouseEvent *event)
{
rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
}
In mainwindow.h :
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui
{
class MainWindow;
}
QT_END_NAMESPACE
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
In mainwindow.cpp :
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsScene>
#include <QGridLayout>
#include "graphicsview.h"
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QGridLayout *gridLayout;
gridLayout = new QGridLayout(centralWidget());
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
auto scene = new QGraphicsScene(this);
graphicsView *_view = new graphicsView();
_view->setScene(scene);
gridLayout->addWidget(_view);
}
MainWindow::~MainWindow()
{
delete ui;
}
The result is this
:
I have a widget that accepts drop. The object which is dragged in this example can be any pdf or text file. The requirement is when the dragged object goes inside my widget, the cursor should be changed into another form.
I did some search here, and there is a way to do it setDragCursor, but this function is of QDrag. I did not create the dragged widget myself and from dropEnterEvent and dropMoveEvent I don't know how to change the cursor.
DragWidget.h
#ifndef DRAGWIDGET_H
#define DRAGWIDGET_H
#include <QFrame>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
class DragWidget : public QFrame
{
public:
DragWidget(QWidget *parent = nullptr);
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
};
#endif // DRAGWIDGET_H
DragWidget.cpp
#include "dragwidget.h"
#include <QMimeData>
#include <QDebug>
DragWidget::DragWidget(QWidget *parent) : QFrame(parent)
{
setMinimumSize(300, 300);
setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
setAcceptDrops(true);
}
void DragWidget::dragEnterEvent(QDragEnterEvent *event)
{
const QMimeData *mimeData = event->mimeData();
if ( mimeData->hasText() || mimeData->hasFormat( "application/json" ) )
{
qDebug()<<mimeData->text();
}
}
void DragWidget::dragMoveEvent(QDragMoveEvent *event)
{
event->acceptProposedAction();
}
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "dragwidget.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
DragWidget *m_dragWidget=nullptr;
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_dragWidget = new DragWidget(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
With the code above, the mouse cursor off course does not change
Do you guys have any idea about this?
I am trying to implement an image editor with some customized image edition tools not present in the Qt image classes. When the user clicks on the image scene to perform some operation, I want the image to be instantly updated in the GUI application, showing in real time to the user the changes (drawing pixels, zooming...). The problem is that the actions to edit the image when clicking can only be done (at least to my knowledge) inside a separate class (in the example I show below, such class is called GraphicsScene), and thus I don't know how to transfer the edited image to the MainWindow class.
In short, I would like to "send" the edited image from the GraphicsScene class to the MainWindow class immediately after the user performs an action to edit the image, and then make the latter one execute the code to update the screen in real time after each user action is performed on the image.
For the sake of clarity, I next show the scheme of the code I have for now.
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Ui::MainWindow *ui;
private slots:
private:
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QApplication>
#include <QMouseEvent>
#include <QGraphicsSceneMouseEvent>
#include "graphicsscene.h"
extern QImage Image_original, Image_modified;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionOpen_Image_triggered()
{
QDir dir;
QString filename=QFileDialog::getOpenFileName(this,
tr("Open Background"),
path,
tr("Images (*.png *.bmp *.jpg *.jpeg);;All files (*.*)"));
Image_original.load(filename);
GraphicsScene * img = new GraphicsScene( this );
img->addPixmap(QPixmap::fromImage(Image_original));
ui->preview->setScene(img);
}
In order to be able to track the coordinates when clicking, and following some suggestions around the net, I created a subclass of QGraphicsScene called GraphicsScene, whose header file is:
graphicsscene.h
#ifndef GRAPHICSSCENE_H
#define GRAPHICSSCENE_H
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QPointF>
#include <QList>
class GraphicsScene : public QGraphicsScene
{
Q_OBJECT
public:
explicit GraphicsScene(QObject *parent = 0);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);
signals:
public slots:
private:
int x, y;
};
#endif // GRAPHICSSCENE_H
Finally, to perform the image editions, the source file associated is:
graphicsscene.cpp
#include "graphicsscene.h"
#include <iostream>
using namespace std;
extern QImage Image_original, Image_modified;
GraphicsScene::GraphicsScene(QObject *parent) :
QGraphicsScene(parent)
{
this->setBackgroundBrush(Qt::gray);
}
void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
QGraphicsScene::mousePressEvent(mouseEvent);
if (mouseEvent->button()==Qt::LeftButton)
{
x=mouseEvent->scenePos().x();
y=mouseEvent->scenePos().y();
}
Image_modified=some_custom_image_editing_code(Image_original, x, y);
}
Ideally, I would like to execute the following action in MainWindow after the mousePressEvent is performed:
img->addPixmap(QPixmap::fromImage(Image_modified));
ui->preview->setScene(img);
I would highly appreciate any idea.
Since you want to click the item containing the pixmap it is not necessary to overwrite the QGraphicsScene mousePressEvent method, since you could click outside the image, it is better to overwrite that method in QGraphicsPixmapItem.
Instead of using extern to access the images, in Qt is better signals and slot, but only the classes that inherit from QObject can have these attributes, unfortunately QGraphicsPixmapItem does not inherit from this, but we can use it as interface.
graphicspixmapitem.h
#ifndef GRAPHICSPIXMAPITEM_H
#define GRAPHICSPIXMAPITEM_H
#include <QGraphicsPixmapItem>
#include <QObject>
class GraphicsPixmapItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
public:
explicit GraphicsPixmapItem(QObject *parent=0);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent * event);
signals:
void newPixmap(const QPixmap p);
};
#endif // GRAPHICSPIXMAPITEM_H
graphicspixmapitem.cpp
#include "graphicspixmapitem.h"
#include <QGraphicsSceneMouseEvent>
GraphicsPixmapItem::GraphicsPixmapItem(QObject * parent):QObject(parent)
{
}
void GraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QPoint p = QPoint(event->pos().x(), event->pos().y());
QPixmap pix = pixmap();
if(!pix.isNull()){
QRect rect(QPoint(), pix.rect().size()/2);
rect.moveCenter(p);
QPixmap modified = pix.copy(rect);
modified = modified.scaled(pix.rect().size(), Qt::KeepAspectRatioByExpanding);
emit newPixmap(modified);
}
QGraphicsPixmapItem::mousePressEvent(event);
}
In the previous code we created the signal newPixmap, this connected it with a slot called onNewPixmap in MainWindow.
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "graphicsscene.h"
#include "graphicspixmapitem.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_actionOpen_triggered();
void onNewPixmap(const QPixmap pixmap);
private:
Ui::MainWindow *ui;
GraphicsPixmapItem *item;
GraphicsScene *scene;
QPixmap original_pixmap;
QPixmap new_pixmap;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsView>
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new GraphicsScene(this);
ui->preview->setScene(scene);
item = new GraphicsPixmapItem;
/*ui->preview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->preview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);*/
scene->addItem(item);
connect(item, &GraphicsPixmapItem::newPixmap, this, &MainWindow::onNewPixmap);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionOpen_triggered()
{
QString path = QDir::homePath();
QString filename=QFileDialog::getOpenFileName(this,
tr("Open Background"),
path,
tr("Images (*.png *.bmp *.jpg *.jpeg);;All files (*.*)"));
original_pixmap = QPixmap(filename);
item->setPixmap(original_pixmap);
}
void MainWindow::onNewPixmap(const QPixmap pixmap)
{
new_pixmap = pixmap;
QFile file("new_file.png");
file.open(QIODevice::WriteOnly);
new_pixmap.save(&file, "PNG");
}
In that slot as test I save the image in the folder where the executable is generated.
In your code I see that you use QImage, if you want to continue using it you can convert QPixmap to QImage with:
new_pixmap.toImage()
The complete example is found here
i am working on QT C++,developing an application that display an image on a label(control) and after click that image the new image will display in other label (control). i create a new project: application->QtWidget Application. then i select class Qdialog. in project file are
- my_qlabel_mouseEvent.pro
and in header folder are
- dialog.h
- my_qlabel.h
and then source folder has files
1: dialog.cpp
2:main.cpp
3: my_qlabel.cpp
and then in form folder has
1: dialog.cpp.
when i add the new class my_qlabel with base class QLabel, type information: QWidget after creating this the setPixmap does not work. its show error the error is that "in constructor 'Dialog::Dialog(QWidget*)' class my_qlabel has no member named setPixmap" please solve this error or reffer me any site or other sources.
**my_qlabel.cpp**
#include "my_qlabel.h"
#include <QPixmap>
my_qlabel::my_qlabel(QWidget *parent) : QWidget(parent)
{
}
void my_qlabel::mouseMoveEvent(QMouseEvent *)
{
emit Mouse_Pos();
}
void my_qlabel::mousePressEvent(QMouseEvent *)
{
emit Mouse_Pressed();
}
void my_qlabel::leaveEvent(QEvent *)
{
emit Mouse_Left();
}
**main.cpp**
#include "dialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
**dialog.cpp**
#include "dialog.h"
#include "ui_dialog.h"
#include "my_qlabel.h"
#include <QPixmap>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QPixmap pix("E:/osld/andgate.png");
ui->lblMouse->setPixmap(pix);
connect(ui->lblMouse, SIGNAL(Mouse_Pressed()), this, SLOT(Mouse_Pressed()));
connect(ui->lblMouse, SIGNAL(Mouse_Pos()), this, SLOT(Mouse_current_pos()));
connect(ui->lblMouse, SIGNAL(Mouse_Left()), this, SLOT(Mouse_left()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::Mouse_current_pos()
{
ui->lblMouse_Current_Event->setText("Mouse Moving");
}
void Dialog::Mouse_Pressed()
{
ui->lblMouse_Current_Event->setText("Mouse Pressed");
}
void Dialog::Mouse_left()
{
ui->lblMouse_Current_Event->setText("Mouse Left");
}
**dialog.h**
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
private slots:
void Mouse_current_pos();
void Mouse_Pressed();
void Mouse_left();
private:
Ui::Dialog *ui;
};
#endif // DIALOG_H
**my_qlabel.h**
#ifndef MY_QLABEL_H
#define MY_QLABEL_H
#include <QWidget>
#include <QMouseEvent>
#include <QEvent>
#include <QDebug>
#include <QPixmap>
class my_qlabel : public QWidget
{
Q_OBJECT
public:
explicit my_qlabel(QWidget *parent = 0);
void mouseMoveEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void leaveEvent(QEvent *);
signals:
void Mouse_Pressed();
void Mouse_Pos();
void Mouse_Left();
public slots:
};
#endif // MY_QLABEL_H
I need some help with connection of signal and slot. this is what i have.
In .h file area is the examplar of the class which inherited from QMdiArea. AddSubWindow is slot of this class, and it works correct with other signal. compiler said
"QObject::connect: No such slot MyMdiArea::AddSubWindow(true) in workspace.cpp:37"
#include "workspace.h"
WorkSpace::WorkSpace(QWidget *parent)
: QWidget(parent)
{
HLayout=new QHBoxLayout;
VLayout=new QVBoxLayout;
TabButton = new QPushButton("Tabbed View");
SimpleButton = new QPushButton("Simple View");
AddButton = new QPushButton("Add Window");
HLayout->addWidget(AddButton);
HLayout->addWidget(TabButton);
HLayout->addWidget(SimpleButton);
str="Title";
area = new MyMdiArea(0,str);
area->setViewMode(QMdiArea::TabbedView);
area->setTabsClosable(true);
area->setTabsMovable(true);
VLayout->addLayout(HLayout);
VLayout->addWidget(area);
connect(AddButton,SIGNAL(clicked()),area,SLOT(AddSubWindow(true)));
this->setLayout(VLayout);
//this->show();
}
WorkSpace::~WorkSpace()
{
}
slot
void MyMdiArea::AddSubWindow(bool i)
{
//QString str="заголовок";
MyWindow *widget = new MyWindow(0,str1);
addSubWindow(widget);
widget->setWindowTitle(str1);
widget->show();
}
h. file
#include <QtWidgets/QMainWindow>
#include "ui_workspace.h"
#include "MyMdiArea.h"
#include "mywindow.h"
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTextBlock>
#include <qstring.h>
class WorkSpace : public QWidget
{
Q_OBJECT
public:
WorkSpace(QWidget *parent = 0);
~WorkSpace();
QHBoxLayout *HLayout;
QVBoxLayout *VLayout;
QPushButton *TabButton;
QPushButton *SimpleButton;
QPushButton *AddButton;
MyMdiArea *area;
QString str;
private:
Ui::WorkSpaceClass ui;
};
MyMdiArea.h
#ifndef MYMDIAREA_H
#define MYMDIAREA_H
#include <QWidget>
#include <QMdiArea>
#include <qmessagebox.h>
#include <qpixmap.h>
#include <qpainter.h>
#include "ui_mymdiarea.h"
class MyMdiArea : public QMdiArea
{
Q_OBJECT
public:
QString str1;
void SendSignal();
MyMdiArea(QWidget *parent,QString str);
~MyMdiArea();
void mouseDoubleClickEvent(QMouseEvent *event);
public slots:
void AddSubWindow(bool t);
signals:
void doubleClicked(bool t);
private:
Ui::MyMdiArea ui;
QPixmap logo;
protected:
void paintEvent(QPaintEvent *event);
};
#endif // MYMDIAREA_H
The problem is:
Signal clicked() has no parameter, but slot AddSubWindow() has a parameter of bool type. That's not allowed in Qt.
try change your code like this
.h
public slots:
void AddSubWindow();
.cpp
void MyMdiArea::AddSubWindow()
{
QString str="заголовок";
MyWindow *widget = new MyWindow(0,str1);
addSubWindow(widget);
widget->setWindowTitle(str1);
widget->show();
}