Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Modifying widgets in constructor
QtWS25 Last Chance

Modifying widgets in constructor

Scheduled Pinned Locked Moved 3rd Party Software
4 Posts 3 Posters 3.2k Views
  • 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.
  • B Offline
    B Offline
    bamboo
    wrote on 12 Dec 2011, 19:45 last edited by
    #1

    I have run into an issue where I try to change some properties for a widget or two (created in Designer) in their parent's constructor and they do not take effect.

    For instance, I have a QwtPlot (part of the Qwt graph package) added to my QMainWindow in designer and I try to change the plot's axis fonts in the QMainWindow's constructor with plot.setAxisFont(int axis, QFont font) but they do not change. Adding an update() or repaint() call after setAxisFont didn't help. The first call in the QMainWindow constructor is setupUi(this) so the QwtPlot widget should be initialized.

    If I wait until the QMainWindow is fully instantiated (e.g. constructor returns) and then call a method which sets the fonts (with the same code) the changes show. I seem to remember having this problem before with a Qt widget (not from Qwt) as well. Anyone know anything about this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on 13 Dec 2011, 14:54 last edited by
      #2

      Hi!

      Can you print the source of your constructor method ?

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bamboo
        wrote on 14 Dec 2011, 00:51 last edited by
        #3

        Sure, here is what I was trying to do:

        @ImageMainWindow::ImageMainWindow(QSharedPointer<ConfigParams> config_params, QMenuBar *main_win_menubar, QWidget *parent) : QMainWindow(parent), ui(new Ui::ImageMainWindow) {
        ui->setupUi(this);

        //plot_title_font and plot_axis_font are QFonts
        plot_title_font_ = ui->histo_plot->font(); //histo_plot is a QwtPlot
        plot_title_font_.setPointSize(PLOT_TITLE_FONT_SIZE); //PLOT_TITLE_FONT_SIZE is const int 8

        plot_axis_font_ = plot_title_font_;

        ui->histo_plot->setAxisFont(QwtPlot::xBottom, plot_axis_font_);
        ui->histo_plot->setAxisFont(QwtPlot::yLeft, plot_axis_font_);
        }@

        and moving it to the showEvent method as follows works:

        @void ImageMainWindow::slt_set_plot_fonts() {
        //plot_axis_font setup in constructor
        ui->histo_plot->setAxisFont(QwtPlot::xBottom, plot_axis_font_);
        ui->histo_plot->setAxisFont(QwtPlot::yLeft, plot_axis_font_);
        }

        void ImageMainWindow::showEvent(QShowEvent *event) {
        static bool been_here = false;

        if (!been_here) {
        slt_set_plot_fonts();
        been_here = true;
        }

        QWidget::showEvent(event);
        }@

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 14 Dec 2011, 09:35 last edited by
          #4

          Sounds like a problem in Qwt to me, to be honest. I think what you were doing in the constructor should work. The only thing I can think about, is that perhaps (speculation) Qwt does not accept setting up axis before you actually told it about the kind of data is need to plot (and what axis there are in that)?

          1 Reply Last reply
          0

          1/4

          12 Dec 2011, 19:45

          • Login

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