Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, August 2007
A QWidgets' width in QToolBar


Message 1 in thread

Hi there,

This is Qt 4.3.0
I'm trying to have the QWidgets of a QToolBar all the same width.
This is how it currently works in our application, and imho it's a bit easier
on the eyes and looks 'cleaner'.
Well, I have this piece of code run in void showEvent(QShowEvent *e) of a
QDialog-derived class after I added all the actions:

      QList<QAction*> a = toolbar.actions();
      int max_widget_size = 0;
      QList<QWidget*> widgets;
      for(QList<QAction*>::iterator i = a.begin(); i != a.end(); ++i)
      {
         QWidget *w = toolbar.widgetForAction(*i);
         if( w->width() > max_widget_size )
            max_widget_size = w->width();
         widgets.push_back(w);
      }
      for(QList<QWidget*>::iterator i = widgets.begin(); i !=
widgets.end(); ++i)
         (*i)->setMinimumWidth(max_widget_size);

This seems to work -- every QWidget has the same width. But the width
is far wider than the widest QWidget normally would be. I've tried executing
exactly that code in a on_button_clicked() so it is executed after the dialog
has been shown completely, and it works exactly like I want it.

Now here's the issue: It seems the QWidgets in the QToolBar will be resized
somewhere after showEvent() runs. When might that be and what chances do
I have to run code to the right time?

Regards,

Daniel Albuschat

-- 
 [ signature omitted ]