Florian Hübner wrote:
> Hi everyone,
> I came across an odd problem with a hidden label today:
>
> I first create the label in my main class with
>
> *******************
> searchHintLabel_ = new QLabel("test");
> searchHintLabel_.hide();
> createMenu();
> *******************
>
> then I call createMenu()
>
> *******************
> private void createMenu() {
> QToolBar tbs = new QToolBar(this);
> tbs.setObjectName("tbs");
> tbs.setWindowTitle(tr("Search Actions"));
> addToolBar(tbs);
>
> tbs.addWidget(searchComboBox_);
> tbs.addWidget(searchHintLabel_);
> tbs.addAction(searchAction_);
> tbs.addAction(openAdvancedSearchAction_);
> }
> *******************
>
> and after I receive the correct signal I call
>
> *******************
> public void displaySearchHint(String text){
> searchHintLabel_.setText(text);
> searchHintLabel_.show();
> searchComboBox_.setFixedWidth(200);
> }
> *******************
>
> The size of the combobox changes correctly and the text of the label
> changes too, but for some reason the label stays hidden.
> I also tried QLabel.setVisible() but it had the same result.
>
> Anybody knows what went wrong here?
Hi Florian,
The problem is that the "thing" that is actually added to the toolbar is
not the QLabel, but a wrapper action, called a QWidgetAction. The action
is by default hidden, as spesified by the visibility of the QLabel, but
does not listen for the visibility of the label afterwards. The widget
action is returned from the addWidget() function, so you can use that
instance to change the visibility of the label in the toolbar.
QAction labelAction;
private void createMenu() {
...
labelAction = tbs.addWidget(searchHintLabel_);
}
public void displaySearchHint(String text) {
...
labelAction.setVisible(true);
}
best regards,
Gunnar
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest