Results 1 to 7 of 7

Thread: Promoting Widget, plotting

  1. #1
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Promoting Widget, plotting

    Hello.

    I have task to plot a few graphics on different widgets. Since I use QCustomPlot I always need to promote this in Qt Designer Form. It is easy to do when you have just one widget where you will plot something, but what if I need a few different plots simultaneously?

    Does the way exist to promote widget from code (not using Qt Designer) or I should use different class (not QCustomPlots).. ?

    Thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Promoting Widget, plotting

    You can just add the QCustomPlots in code.
    The promote feature is only needed if you want to insert the widget in designer.

    Alternatively you can create a designer plugin to be able to have the widget in the toolbox: http://doc.qt.io/qt-5/designer-creat...m-widgets.html

    Cheers,
    _

  3. #3
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Promoting Widget, plotting

    You can just add the QCustomPlots in code.
    But I don't need an object. I want just to plot and I do it using QCustomPlots on widget. I do not understand how to connect the new window with QCustomPlot without using Qt Designer Form in order to be able to plot on the new Window.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. QPushButton *ok = new QPushButton("Create new!",this) ;
    10.  
    11.  
    12. connect(ok,SIGNAL(clicked(bool)),SLOT(Born()));
    13.  
    14. }
    15.  
    16. MainWindow::~MainWindow()
    17. {
    18. delete ui;
    19. }
    20.  
    21. void MainWindow::Born()
    22. {
    23. QMainWindow *NewWindow=new QMainWindow;
    24.  
    25. //how to plot here using QCustomPlot?
    26.  
    27. // NewWindow->setLayout();
    28. NewWindow->show();
    29. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Promoting Widget, plotting

    Quote Originally Posted by Blitzor DDD View Post
    But I don't need an object.
    How do you expect to use a class like QCustomPlot without creating an object of that class?

    Quote Originally Posted by Blitzor DDD View Post
    I want just to plot and I do it using QCustomPlots on widget
    So you are not using QCustomPlot widget?
    Then what did you use promoting for?

    Quote Originally Posted by Blitzor DDD View Post
    I do not understand how to connect the new window with QCustomPlot without using Qt Designer Form in order to be able to plot on the new Window.
    If the window you are plotting on is not a QCustomPlot widget, what exactly is it?
    Your own QWidget subclass?

    Quote Originally Posted by Blitzor DDD View Post
    Qt Code:
    1. void MainWindow::Born()
    2. {
    3. QMainWindow *NewWindow=new QMainWindow;
    4.  
    5. //how to plot here using QCustomPlot?
    6.  
    7. // NewWindow->setLayout();
    8. NewWindow->show();
    9. }
    To copy to clipboard, switch view to plain text mode 
    Well, if you would use QCustomPlot as a widget and not draw on whatever you are using right now, you could simply create an instance of QCustomPlot and set it as NewWindow's central widget.

    But that should also work with whatever widget you are using right now.

    Cheers,
    _

  5. #5
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Promoting Widget, plotting

    http://www.qcustomplot.com/index.php...ials/settingup - I just promote widget to QCustomPlot and use it through ui->widget->name_of_function()

    Well, if you would use QCustomPlot as a widget and not draw on whatever you are using right now, you could simply create an instance of QCustomPlot and set it as NewWindow's central widget.
    Could you provide an example please?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Promoting Widget, plotting

    Could you provide an example please?
    OK, if you did in fact follow the instructions at the link you posted, then what you did resulted in a form with an instance of a QCustomPlot object that is named "widget" (if the code you posted is the same as what you did).

    So "ui->widget " is a pointer to an instance of QCustomPlot, and it lives in the form that you are using as the central widget of your MainWindow. If you want to use it, then follow this tutorial, except that every place it uses the variable named "customplot", you use "ui->widget".

    It would probably help you if you chose better names for your QWidget instances than "widget", like in this case maybe "customplot".
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Promoting Widget, plotting

    Quote Originally Posted by Blitzor DDD View Post
    Could you provide an example please?
    Example for calling the new operator on a class or for calling a method on an object?

    Hmm, you already called the new operator on the QMainWindow class so I guess you need an example on how to call a method.

    Qt Code:
    1. NewWindow->setCentralWidget(pointerToAWidgetInstance);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 23rd December 2010, 09:35
  2. Promoting to custom widget
    By cia.michele in forum Newbie
    Replies: 2
    Last Post: 26th September 2010, 11:38
  3. Promoting widget in Designer
    By evident in forum Qt Programming
    Replies: 5
    Last Post: 24th July 2010, 22:06
  4. Error when promoting a custom widget
    By engin in forum Qt Tools
    Replies: 1
    Last Post: 15th December 2006, 16:00
  5. Promoting a custom widget derived from QWidget Qt4
    By high_flyer in forum Qt Tools
    Replies: 1
    Last Post: 2nd March 2006, 18:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.