Results 1 to 13 of 13

Thread: Qt custom slot does not work

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt custom slot does not work

    Quote Originally Posted by ChrisW67 View Post
    Put the graph widget and table widget into a QStackedWidget, which is the central widget of the QMainWindow, and have your menu actions switch between the two pages in the stack.
    Thank you for your reply. Do you mind giving me at bit more details (I am really new to Qt/Qwt/NightCharts). If you look at my code earlier I have used plotData() (a data plot with Qwt) and paint() (a pie chart with NightCharts) as two slots which are to be activated with two different menu-clicks.
    Thank you for your time.

  2. #2
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt custom slot does not work

    Hallo All,
    I still could not figure out the above. In brief, I have 2 menu actions, for ex. Total Traffic & Network Layer- please see attached figure. The first one will trigger plotData() that draws a plot (Bandwidth Graph), and the second one will trigger a pie chart. The problem is that the pie chart is always shown behind the plot.

    As suggested by @ChrisW67 I tried to implement but still no luck.

    screen.jpg

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt custom slot does not work

    You are painting on the wrong widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt custom slot does not work

    Quote Originally Posted by wysota View Post
    You are painting on the wrong widget.
    Thank you for your reply. Could you please write me a bit details...I don't get it.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt custom slot does not work

    Your screenshot looks like you have a widget in your main window which is some kind of chart and at the same time you are trying to paint another chart directly in the main window widget itself. Since the first chart is a child widget of the main window, its contents will always be above the contents of the main window. Note that I'm basing my thoughts only on the screenshot as you didn't share any meaningful code with us.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt custom slot does not work

    Quote Originally Posted by wysota View Post
    Your screenshot looks like you have a widget in your main window which is some kind of chart and at the same time you are trying to paint another chart directly in the main window widget itself. Since the first chart is a child widget of the main window, its contents will always be above the contents of the main window. Note that I'm basing my thoughts only on the screenshot as you didn't share any meaningful code with us.
    Thank you for your reply. You are right- both are basically drawn on main window. But I still can't figure out how to access the widget for NightCharts (it's a class) (please see the code below) so that it can be added in QStackedWidget.


    In mainwindow.cpp:
    [code]
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ........
    stackedWidget = new QStackedWidget;
    stackedWidget->addWidget(widget1);//here goes Qwt plot widget
    stackedWidget->addWidget(widget2); //here goes pie chart widget
    ......
    }

    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent *e)
    2. {
    3. QWidget::paintEvent(e);
    4. QPainter painter;
    5. QFont font;
    6. painter.begin(this);
    7. Nightcharts PieChart;
    8. PieChart.setType(Nightcharts::Dpie);//{Histogramm,Pie,DPie};
    9. PieChart.setLegendType(Nightcharts::Vertical);//{Round,Vertical}
    10. PieChart.setCords(100,100,this->width()/1.5,this->height()/1.5);
    11. PieChart.addPiece("Item1",QColor(200,10,50),34);
    12. PieChart.addPiece("Item2",Qt::green,27);
    13. PieChart.addPiece("Item3",Qt::cyan,14);
    14. PieChart.addPiece("Item4",Qt::yellow,7);
    15. PieChart.addPiece("Item5",Qt::blue,4);
    16. PieChart.draw(&painter);
    17. PieChart.drawLegend(&painter);
    18. }
    To copy to clipboard, switch view to plain text mode 

  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: Qt custom slot does not work

    Why on earth are you overriding MainWindow:aintEvent()?

    Cheers,
    _

  8. #8
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt custom slot does not work

    Finally I got it right...Thank you everybody who helped me to resolve this.

Similar Threads

  1. Slot doesn't work in new window
    By mohjlir in forum Newbie
    Replies: 2
    Last Post: 27th January 2011, 10:50
  2. slot no work in another class
    By Aronax in forum Qt Programming
    Replies: 9
    Last Post: 11th January 2011, 10:21
  3. Replies: 5
    Last Post: 14th September 2010, 21:13
  4. Slot doesn't seem to work
    By waynew in forum Newbie
    Replies: 3
    Last Post: 10th November 2009, 09:54
  5. copy() slot doesn't work
    By Macok in forum Qt Programming
    Replies: 3
    Last Post: 14th February 2009, 10:55

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
  •  
Qt is a trademark of The Qt Company.