Unsolved Qwidget plugin
-
@hjohn Why do you want to access the main window directly from the plug-in? It would be better to communicate via signals/slots.
-
@hjohn said in Qwidget plugin:
@raven-worx I don't think so
you don't think what?!
If you want to use it you have to tell the compiler/linker tell where to find it... -
@jsulm I am implementing qwidgetplugin with reference of http://doc.qt.io/qt-5/qtdesigner-customwidgetplugin-example.html
-
@hjohn You are aware that this link describes how to implement a plug-in for QtDesigner? Do you want a plug-in for QtDesigner or for your application? And in that example I can't see the plug-in using the main window. So again: why do you want to access main window from your plug-in directly?
-
@jsulm yeah i want plug-in for Qt designer.i have implemented same way as mentioned. Here is aq misunderstanding of "mainwindow" name. I have just give different name to the class.the definition and characteristics are same.
mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include<QWidget> #include<QObject> #include<QtUiPlugin/qdesignerexportwidget> class MainWindow : public QWidget { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); protected: void paintEvent(QPaintEvent *event) override; }; #endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h" #include <QMouseEvent> #include <QPainter> #include <QTime> #include <QTimer> MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, QOverload<>::of(&QWidget::update)); timer->start(1000); setWindowTitle(tr("Analog Clock")); resize(200, 200); } void MainWindow::paintEvent(QPaintEvent *) { static const QPoint hourHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -40) }; static const QPoint minuteHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -70) }; QColor hourColor(127, 0, 127); QColor minuteColor(0, 127, 127, 191); int side = qMin(width(), height()); QTime time = QTime::currentTime(); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); painter.scale(side / 200.0, side / 200.0); painter.setPen(Qt::NoPen); painter.setBrush(hourColor); painter.save(); painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0))); painter.drawConvexPolygon(hourHand, 3); painter.restore(); painter.setPen(hourColor); for (int i = 0; i < 12; ++i) { painter.drawLine(88, 0, 96, 0); painter.rotate(30.0); } painter.setPen(Qt::NoPen); painter.setBrush(minuteColor); painter.save(); painter.rotate(6.0 * (time.minute() + time.second() / 60.0)); painter.drawConvexPolygon(minuteHand, 3); painter.restore(); painter.setPen(minuteColor); for (int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(92, 0, 96, 0); painter.rotate(6.0); } }
-
@hjohn Then please add your mainwindow.h|cpp to the pro file as @raven-worx already suggested.
-
@jsulm okay thanks.. i will try as u have guided.
one last question how Qdesigner is differ from normal gui application. -
@hjohn It is simply a Qt application. But it provides a plug-in interface to add functionality to it. I mean functionality specific for QtDesigner.
-
@jsulm Qtdesigner does not contain any .ui file.i mean it is custom implementation .am i right?
In other plugins example the project having subproject.for ex: gui application is the parent project and plugin lib contain in sub-project.Can we use same method in this qtdesigner plugin.
-
@hjohn I'm not sure I understand the question.
QtDesigner is a Qt application. You can download its source code if you need it.
The examples simply combine the main app and the plug-in in one project. In your case you can't do this as you would need to add your plug-in to QtDesigner source code. But it is not necessary, just follow the example you posted before. -
@jsulm thanks..:)