PDA

View Full Version : QTabWidget->setCornerWidget() unexpected resize.



hickscorp
8th December 2006, 01:13
Hello people,

I'm experiencing some strange behavior with the following set up:
- I'm using QT 4.2.x (Replace .x with the standard Edgy packaged version).
- I create a class which herits from QTabWidget, and dynamicaly creates sub widgets (Tabs).
- I also have created a little other QWidget derived class (With QTDesigner, named CEditorTabButtons) then a subclass which implements it. It is a simple qwidget with inside several QToolButtons. All the QToolsButtons are layed out with a default horizontal boxing.
- In the constructor of the "Tab manager" class, i do:

pButtonsBar = new CEditorTabButtonsImpl(this);
setCornerWidget(pButtonsBar);

Then here comes the strange thing:
If i have only one tab in the tab container, the "corner buttons" are kind of stacked (If i give them a minimal size). They are also resized to very tiny size (If i give them no minimal size). After i add another tab, the buttons have almost their right size, and with more than 2 tabs they have the right size and stop changing size (Until i remove tabs again, they becomes small).

So i tried to tell my CEditorTabButtonsImpl to have a fixed size, the result is that when i only have 1 tab, the box "slides" to the right, and as a result i'm only able to see the 2 first buttons (The others are out of the window).

Resizing the main application window does nothing.

Anyone has a clue on what i'm doing wrong here?

Thanks a lot,
Pierre.

[EDIT:] Just to make thinks a bit more clear: what i'm trying to achieve is a simple tabbed based text editor. So the tools buttons in the tab bar i'm talking about are like such this kind of tool usualy have (With save, open, new close icons). I hope you'll see what i mean :)
[EDIT2:] Just added 4 screens of what's appening :)

hickscorp
8th December 2006, 12:03
Up? :o
I have attached pictures of the visual i have in my previous post.
If no one can help, can someone please gives me a clue on where to search for this information?

Thanks,
Pierre.

hickscorp
13th December 2006, 13:46
Up?...

Should i ask to the QT programming team, or is my mistake so obvious that people doesn't want to answer ? :rolleyes:

Thanks,
Pierre.

jpn
13th December 2006, 14:43
I'm sure a minimal compilable example reproducing the problem would raise people's interest towards the problem.. ;)

hickscorp
19th December 2006, 19:18
Hello JPN and thanks for your suggestion.

I will try to make here an example closest as i can to what i'm trying to do.

So first, i have created this .UI, which is the content i want to appear in my tabs:


<ui version="4.0" >
<class>CEditorTab</class>
<widget class="QWidget" name="CEditorTab" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>681</width>
<height>611</height>
</rect>
</property>
<property name="windowTitle" >
<string>Editor Tab</string>
</property>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>0</number>
</property>
<item>
<widget class="QTextEdit" name="txtEditor" >
<property name="font" >
<font>
<family>Monospace</family>
<pointsize>8</pointsize>
<weight>50</weight>
<bold>false</bold>
<antialiasing>true</antialiasing>
<kerning>true</kerning>
</font>
</property>
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWrapMode" >
<enum>QTextEdit::NoWrap</enum>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>txtEditor</tabstop>
</tabstops>
<resources>
<include location="Artwork/Resources.qrc" />
</resources>
<connections/>
</ui>


Then, i have created this .UI, which is a QWidget containing various buttons i want to show on the top right corner of my QTabWidget:


<ui version="4.0" >
<class>CEditorTabButtons</class>
<widget class="QWidget" name="CEditorTabButtons" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>22</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle" >
<string>Editor Buttons</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>2</number>
</property>
<item row="0" column="5" >
<widget class="QToolButton" name="btnClose" >
<property name="minimumSize" >
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="Artwork/Resources.qrc" >:/Images/RedCross.png</iconset>
</property>
</widget>
</item>
<item row="0" column="4" >
<widget class="QToolButton" name="btnNew" >
<property name="minimumSize" >
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="Artwork/Resources.qrc" >:/Images/NewFile.png</iconset>
</property>
</widget>
</item>
<item row="0" column="3" >
<widget class="QToolButton" name="btnOpen" >
<property name="minimumSize" >
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="Artwork/Resources.qrc" >:/Images/Folder.png</iconset>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QToolButton" name="btnSaveAll" >
<property name="minimumSize" >
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="Artwork/Resources.qrc" >:/Images/SaveAll.png</iconset>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QToolButton" name="btnSave" >
<property name="minimumSize" >
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="Artwork/Resources.qrc" >:/Images/Save.png</iconset>
</property>
</widget>
</item>
<item row="0" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>118</width>
<height>22</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="Artwork/Resources.qrc" />
</resources>
<connections/>
</ui>


Then i have this class (Which is simplified for the example):


#ifndef CEditorTabBar_h
#define CEditorTabBar_h

#include <QTabWidget>

// This is the little class containing the corner buttons, which i have derived to put some file open / close code in it...
class CEditorTabButtonsImpl;
class CEditorTabImpl;
class QToolButton;
class QStringList;

class CEditorTabBar :
public QTabWidget {

Q_OBJECT

public:
// Constructor.
CEditorTabBar(QWidget* Parent=0) :
QTabWidget(parent) {

pButtonsBar = new CEditorTabButtonsImpl(this);
setCornerWidget(pButtonsBar);
}
// Destructor etc also....

cPath);

// Then only slots and signals here.
};

#endif


Then on my main window class, i have code similar to this:


QFont cLittleFont;
cLittleFont.setPointSize(7);
pEditorTabBar = new CEditorTabBar(this);
pEditorTabBar->setFont(cLittleFont);
setCentralWidget(pEditorTabBar);


It creates the Tab Bar, but as shown on pictures on my first thread, the corner buttons are messed up...

Here we are, i hope this will help helping me :)
Thanks,
Pierre.

wysota
19th December 2006, 23:29
Please attach large amounts of code as a file archive instead of pasting it directly in your post :)

hickscorp
20th December 2006, 13:16
Hello Wysota,

I can't edit my post to do as you suggest, any way to delete the thread so i can create a "clean" one?

Thanks,
Pierre.

wysota
20th December 2006, 14:12
There is no need for that - what is done is done.