PDA

View Full Version : Custom TabWidget button



mero
10th February 2011, 04:58
How can I create tab "+" like in firefox ?
5912

I write something like this, but it looks different than in firefox

.cpp


TabManager::TabManager(QWidget *parent) : QTabWidget(parent)
{
tab = tabBar();
...
this->addTab(new QWidget(), QIcon("plus.png"), "");
...
}


.h


class TabManager : public QTabWidget
{
Q_OBJECT
public:
TabManager(QWidget *);

private:
QTabBar *tab;


result is:

5911

so question is - do I need to change paint event for QTabWidget or QTabBar ?
or maybe there is another way to do that ?

wysota
12th February 2011, 00:39
If you want a direct equivalent then I'd add a tool button to the tab bar and reposition it as necessary.

Viper666
1st August 2012, 14:18
So i will not make new thread my question is: How i can give QMenu and QTabBar to Window frame like in Firefox 8081 and how i can style frame i don't mean QFrame but Window frame for example GOM Player hasn't got windows's usualy frame but it has it's frame

d_stranz
1st August 2012, 17:26
I would start by creating a custom QWidget (derived from QTabBar) that contains both a QTabBar and a QToolBar widget in a layout. Then, derive a custom QTabWidget class that replaces its native QTabBar with an instance of your custom tab bar class (see QTabWidget::setTabBar()). This is a protected function, so you are forced to derive a new QTabWidget class. You would probably need to do that anyway, because you will be changing the tool bar contents depending on what is being displayed in a specific tab.

Viper666
1st August 2012, 17:37
thanks and how i can add toolbar to QWidget i try some thinks but they don't work

Added after 5 minutes:


I would start by creating a custom QWidget (derived from QTabBar) that contains both a QTabBar and a QToolBar widget in a layout. Then, derive a custom QTabWidget class that replaces its native QTabBar with an instance of your custom tab bar class (see QTabWidget::setTabBar()). This is a protected function, so you are forced to derive a new QTabWidget class. You would probably need to do that anyway, because you will be changing the tool bar contents depending on what is being displayed in a specific tab. this isn't quite what i want because still stay window's frames. What you wrote is good but it will not look good i want tabbar in frame

I know how make QToolBar but i don't know how i can dock it to Top when i create toolbar in Widget
QToolbar *bar= new QToolbar("toolbar",this); it make toolbar but the toolbar size is about 2x2 but i want toolba like toolbar in QMainWindow

Viper666
1st August 2012, 22:27
ok you can forget what i say. Now i have toolbar
QToolbar *bar= new QToolbar("toolbar",this);8084 but i want dock it to top like 8083

d_stranz
3rd August 2012, 17:10
// MainWindow.cpp constructor:

QToolBar *bar = new QToolBar( "toolbar", this );
QDockWidget * dock = new QDockWidget( "dockwidget", this );
dock->setAllowedAreas( Qt::TopDockWidgetArea );
dock->setFloating( false );
dock->setWidget( toolbar );

Viper666
3rd August 2012, 18:55
It's don't work like i want. I have QWidget and i want add toolbar to the Widget and i want same toolbar like in QMainWindow do you understand what i mean ???

wysota
4th August 2012, 02:59
Then why don't you use QMainWindow instead of QWidget as your base class?

Viper666
4th August 2012, 13:34
I found how to solve it
QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->addWidget(toolBar);
vbox->setContentsMargins(0,0,0,0);
vbox->setSpacing(0);
setLayout(vbox); this is what i need :D