PDA

View Full Version : QTabWidget::setCornerWidget()



michael
8th June 2006, 15:47
This isn't really that important as I ran into this problem in a program I was writing simply because I was bored. Ok, I admit, I have no life.

Anyway I was wondering if anyone else has ran into the same problem.

I have a QTabWidget with which I add tabs via a button on the toolbar like in Firefox. Also like firefox I added a close button to close the open tabs to the QTabWidget using a QToolButton and passing it to QTabWidget::setCornerWidget().

In Windows this works fine and the button shows up at the top right of the QTabWidget as expected. However in Linux it spits the following message out to the console and reparents the QToolButton causing the button to show up at the top right of the tab pages themselves instead of the top right of the entire QTabWidget. Imagine the button being where it should be then moving it straight down a distance of the height of the button and another half.
The information given in the console window is:


QLayout::addChildWidget: QToolButton in wrong parent; moved to correct parent

That above is what happens when I set the QTabWidget as the QToolButton's parent. If I try setting the QTabWidget::QTabBar as the parent it will issue the same error to the console except the button does not show up at all.

As I said this isn't an urgent matter or anything as I stumbled across this while writing something out of boredom. However, I am curious as to why it is working under Windows and not linux. Anyone know, or can at least tell me what the parent of the QToolButton should be for it to work?

This is using Qt 4.0.0 with gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)

Knowing me it is probably something really stupid that makes me look like a moron. But hey, thats life. ;)

-Michael

jacek
8th June 2006, 16:25
This is using Qt 4.0.0 with gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)
Better try Qt 4.1.3. Qt Assistant has buttons in both corners of the QTabWidget --- you could check how did the Trolls do that.

michael
8th June 2006, 17:29
Better try Qt 4.1.3. Qt Assistant has buttons in both corners of the QTabWidget --- you could check how did the Trolls do that.

OWell. I set it up the exact same way they did except it appears they set the parent of the QToolButton to the QTabWidgets parent. More precisely they set the QTabWidget up in a ui file and then subclassed QWidget and set up the ui in that new widget which was obviously set as the parent for the ui form for the tabwidget. In the widget they created is where they set up the buttons and parented them to that widget and then called ui.tab->setCornerWidget(newTabButton, Qt::<some corner>); to put the button in the top corner. Not sure why they did it this way, but I tried doing that and ended up with the same problem. Must have been a bug in 4.0.0 although their assistant seemed to compile with 4.0.0 fine. I find it very strange indeed. I suppose I will have to download the latest version and take the time to compile it and see if it works, although I am probably missing something really obvious.

Michael

michael
8th June 2006, 21:13
Well, it compiles (and works) just fine with Qt 4.1.3 so it must have been a problem in Qt 4.0.0, or perhaps with kubuntu's install of it in any case. I suppose that is what a person gets for using an outdated version. ;)

michael