Question

I want to use a common control (QTreeView) in two different tab pages in QTabWidget. how to do this ?

I added a tabwidget and controls in tab pages in Qt designer. using qt creator version 2.4.1 in Win 7.

Was it helpful?

Solution

You can't have the same QTreeView in two different QTabWidget pages. When you add any widget to a layout, that layout takes ownership of the widget. Since there can only be one owner, you're stuck with one parent per widget.

But you can fake it. Give your main page a grid layout. Put a QTabBar running along the top, your QTreeView on the left (or wherever), and a QStackedLayout on the right. Connect the tab bar and the stacked layout so changing tabs in the bar changes the visible page in the stack layout.

That should be just what you're looking for - just be prepared to fight with QTabBar to get it to display like you want it to...

Alternatively, just live with having two separate tree views - they'll both be viewing the same model, after all, so the bulk of the data won't be duplicated. Saves you a fight with QTabBar, too.

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top