QTabWidget set current tab by tab name?
-
@lansing
I have already answered that in the second part of my post.
You really ought know what you're doing withQWidget
s versusQWidget *
s instead of randomly tyrying things and getting errors, basic C++.Without correcting that (which I think you should, but as I said that's a separate matter), I am not sure but you may be able to make it work from where you are now via
int foundIndex = m_ui->myTabWidget->indexOf(&*it);
-
The FilterWidget is a struct storing a few widgets and some properties, those widgets has pointers.
struct FilterWidget { ImageFilter* imageFilter; TextFilter* textFilter; QString tabName; }; QVector<FilterWidget> m_filterWidgetVector;
indexOf(&*it)
returns the errorerror: cannot initialize a parameter of type 'QWidget *' with an rvalue of type 'FilterWidget *'
-
@lansing
Then I give up. I don't know what you think you are doing. You know thatmyTabWidget->indexOf()
takes aQWidget *
as the widget to try to find, and you are passing it somestruct
(which you have unadvisedly chosen to nameFilterWidget
[and also how can you possibly make a member namedtabName
as of typeint
?]) that has nothing to do with a widget, so how do you expect it to work? Like I wrote, you're not supposed to bung random things in and see what happens, you really need to understand what is going on to write the correct code.... -
@lansing
Hi
The indexOf can find the widgets you insert to tabWidget with
m_ui->myTabWidget->addTab(filterWidget, tabName);so you can find that index again with m_ui->myTabWidget->indexof(filterWidget)
struct FilterWidget cannot be used in this context.
But i wonder how
ImageFilter* imageFilter;
TextFilter* textFilter;
relates to the filterWidget you use with addTab
is it store in imagefilter or textfilter? -
@lansing
Ok so from a FilterWidget item you can find the
tab index by
m_ui->myTabWidget->indexof(filterWidgetENTRY.imageFilter )
or
int foundIndex = m_ui->myTabWidget->indexOf(it.imageFilter ); // maybe need * in front -
This post is deleted!
17/17