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. [SOLVED]can anyone tell me how to scale qwtPlot in a window

[SOLVED]can anyone tell me how to scale qwtPlot in a window

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.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.
  • S Offline
    S Offline
    silent_missile
    wrote on last edited by
    #1

    Hello, I'm using qwt to help my work, but I meet some troubles.

    I put a tabWidget in MainWindow, and put qwtPlot in each tab, when I scale the MainWindow, the tab can scale with the window, but the qwtPlot can't scale together, can anybody tell me how to align them?

    1 Reply Last reply
    0
    • TheBadgerT Offline
      TheBadgerT Offline
      TheBadger
      wrote on last edited by
      #2

      The QwtPlot inside the tab, is it inside a layout?
      Thus you should have the Tab, then a layout and in the layout the QwtPlot?

      For me this is working very well to scale the widget


      Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

      1 Reply Last reply
      0
      • S Offline
        S Offline
        silent_missile
        wrote on last edited by
        #3

        sorry Badger, I didn't apply any layout in the mainwindows or the tabwidget.

        the tabwidget is the centerwidget, and the qwtplot is now the only item inside the tab, I used

        @new qwtPlot(tabwidgets->widget(0))@

        to attach the qwtPlot to tabWidget. it can display, but can't scale with the mainwindow together

        1 Reply Last reply
        0
        • TheBadgerT Offline
          TheBadgerT Offline
          TheBadger
          wrote on last edited by
          #4

          That might be the problem, what I normally do if I create widgets at run time is the following:
          @
          /* Check if the widget that should contain the new widget have a layout, if it does have one, delete and create a new one depending on our needs. /
          if(tabwidgets->widget(0)->layout() != NULL) {
          delete tabwidgets->widget(0)->layout();
          }
          /
          Create a Horizontal, Vertical or any other required layout for the widget*/
          QHBoxLayout* myLayout= new QHBoxLayout(tabwidgets->widget(0));
          /* Create the plot and add it to the layout */
          myLayout->addWidget(new qwtPlot(NULL));
          @

          This way the plot is in the layout of the widget and it will resize with the widget.

          Instead of deleting the layout one can also just get the current one and add the plot to it, but then you are not sure what type of layout it is.

          Hope this helps and is not too late :)

          Edit: added missing bracket to the code


          Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

          1 Reply Last reply
          0
          • S Offline
            S Offline
            silent_missile
            wrote on last edited by
            #5

            thank you, it works well,

            at first it warns qwtPlot is not a QWidget, but I add positions like

            @myLayout->addWidget(new qwtPlot(tabwidgets->widget(0)), 0, 1);@

            it works

            1 Reply Last reply
            0
            • TheBadgerT Offline
              TheBadgerT Offline
              TheBadger
              wrote on last edited by
              #6

              I am glad that it works.

              Just a comment, from my understanding, when adding the widget to the layout, the layout will take ownership of the widget. If this is correct then you do not need to pass the tabwidgets->widget(0) to the constructor of the plot, you can just pass NULL because it will in any case transfer the ownership to the layout as soon as it is added.

              Have a good day :)


              Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

              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