Results 1 to 3 of 3

Thread: Displaying new widget on the another one

  1. #1
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    18
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Displaying new widget on the another one

    Hi

    I have a widget container in my mainwindow.ui and two push buttons. Buttons are responsible to display chart on a widget (exactly piechart). One button has some data, the second one has different. In a nutshell, one button one chart.
    The point is that I want to display charts in one widget container according which button has been clicked. If i push button1 it should display piechart number 1 on the widget. If i push button2 it should display piechart2 (in widget cointainer)
    And it should be possible to push buttons multiple times and every time the proper chart should be displayed.

    It looks like this. Now the button1 is clicked, so it display chart WYDATKI. And when I push button2 it should display another chart, in the same place.

    widget.PNG

    my code for button1 (for button2 is the same, but with different data)

    Qt Code:
    1. void MainWindow::on_PieChart_pushButton_Przychody_clicked()
    2. {
    3.  
    4. QChart *chart = kategoriePieChart::makePieChart("przychody"); // function makePieChart return chart with data
    5. QChartView *chartView = new QChartView(chart);
    6.  
    7. QVBoxLayout *mainLayout = new QVBoxLayout;
    8. mainLayout->addWidget(chartView);
    9.  
    10. ui->widget_piechart->setLayout(mainLayout);
    11. }
    To copy to clipboard, switch view to plain text mode 

    I tried using widget->hide() and widget->show() but it's probably not the valid solution

  2. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Displaying new widget on the another one

    You may use QStackedLayout, add widgets and use void setCurrentIndex(int index) on button click to show the appropriate widget.
    Last edited by rawfool; 22nd November 2016 at 15:27. Reason: spelling corrections

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Displaying new widget on the another one

    I would recommend to use QStackedWidget instead of QStackedLayout.

    Cheers,
    _

Similar Threads

  1. Processing and Displaying Image on Widget
    By mhb88 in forum Qt Programming
    Replies: 13
    Last Post: 15th April 2016, 10:24
  2. Replies: 7
    Last Post: 2nd December 2013, 16:06
  3. Displaying LCD Widget of Qt in QML
    By TheIndependentAquarius in forum Qt Quick
    Replies: 0
    Last Post: 22nd October 2013, 11:23
  4. Displaying a eml file in a widget
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2013, 17:36
  5. Displaying 1 widget at time
    By afflictedd2 in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2008, 15:31

Tags for this Thread

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.