Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qwidget plugin
Forum Updated to NodeBB v4.3 + New Features

Qwidget plugin

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 4 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H hjohn

    @raven-worx I don't think so

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #13

    @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...

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    0
    • jsulmJ jsulm

      @hjohn Why do you want to access the main window directly from the plug-in? It would be better to communicate via signals/slots.

      H Offline
      H Offline
      hjohn
      wrote on last edited by
      #14

      @jsulm I am implementing qwidgetplugin with reference of http://doc.qt.io/qt-5/qtdesigner-customwidgetplugin-example.html

      jsulmJ 1 Reply Last reply
      0
      • H hjohn

        @jsulm I am implementing qwidgetplugin with reference of http://doc.qt.io/qt-5/qtdesigner-customwidgetplugin-example.html

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #15

        @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?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        H 1 Reply Last reply
        0
        • jsulmJ jsulm

          @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?

          H Offline
          H Offline
          hjohn
          wrote on last edited by hjohn
          #16

          @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);
              }
          }
          
          
          jsulmJ 1 Reply Last reply
          0
          • H hjohn

            @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);
                }
            }
            
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #17

            @hjohn Then please add your mainwindow.h|cpp to the pro file as @raven-worx already suggested.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            H 1 Reply Last reply
            0
            • jsulmJ jsulm

              @hjohn Then please add your mainwindow.h|cpp to the pro file as @raven-worx already suggested.

              H Offline
              H Offline
              hjohn
              wrote on last edited by hjohn
              #18

              @jsulm okay thanks.. i will try as u have guided.
              one last question how Qdesigner is differ from normal gui application.

              jsulmJ 1 Reply Last reply
              0
              • H hjohn

                @jsulm okay thanks.. i will try as u have guided.
                one last question how Qdesigner is differ from normal gui application.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #19

                @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.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @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.

                  H Offline
                  H Offline
                  hjohn
                  wrote on last edited by
                  #20

                  @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.

                  jsulmJ 1 Reply Last reply
                  0
                  • H hjohn

                    @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.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #21

                    @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.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply
                    2
                    • jsulmJ jsulm

                      @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.

                      H Offline
                      H Offline
                      hjohn
                      wrote on last edited by
                      #22

                      @jsulm thanks..:)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved