Results 1 to 10 of 10

Thread: Custom TabWidget button

  1. #1
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Custom TabWidget button

    How can I create tab "+" like in firefox ?
    plusff.png

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

    .cpp
    Qt Code:
    1. TabManager::TabManager(QWidget *parent) : QTabWidget(parent)
    2. {
    3. tab = tabBar();
    4. ...
    5. this->addTab(new QWidget(), QIcon("plus.png"), "");
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    .h
    Qt Code:
    1. class TabManager : public QTabWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. TabManager(QWidget *);
    6.  
    7. private:
    8. QTabBar *tab;
    To copy to clipboard, switch view to plain text mode 

    result is:

    plus.png

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom TabWidget button

    If you want a direct equivalent then I'd add a tool button to the tab bar and reposition it as necessary.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom TabWidget button

    So i will not make new thread my question is: How i can give QMenu and QTabBar to Window frame like in Firefox tab.png 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

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Custom TabWidget button

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom TabWidget button

    thanks and how i can add toolbar to QWidget i try some thinks but they don't work


    Added after 5 minutes:


    Quote Originally Posted by d_stranz View Post
    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
    Qt Code:
    1. QToolbar *bar= new QToolbar("toolbar",this);
    To copy to clipboard, switch view to plain text mode 
    it make toolbar but the toolbar size is about 2x2 but i want toolba like toolbar in QMainWindow
    Last edited by Viper666; 1st August 2012 at 17:34.

  6. #6
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom TabWidget button

    ok you can forget what i say. Now i have toolbar
    Qt Code:
    1. QToolbar *bar= new QToolbar("toolbar",this);
    To copy to clipboard, switch view to plain text mode 
    toolbar.png but i want dock it to top like toolbar2.png
    Attached Images Attached Images

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Custom TabWidget button

    Qt Code:
    1. // MainWindow.cpp constructor:
    2.  
    3. QToolBar *bar = new QToolBar( "toolbar", this );
    4. QDockWidget * dock = new QDockWidget( "dockwidget", this );
    5. dock->setAllowedAreas( Qt::TopDockWidgetArea );
    6. dock->setFloating( false );
    7. dock->setWidget( toolbar );
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #8
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom TabWidget button

    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 ???

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom TabWidget button

    Then why don't you use QMainWindow instead of QWidget as your base class?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom TabWidget button

    I found how to solve it
    Qt Code:
    1. QVBoxLayout* vbox = new QVBoxLayout(this);
    2. vbox->addWidget(toolBar);
    3. vbox->setContentsMargins(0,0,0,0);
    4. vbox->setSpacing(0);
    5. setLayout(vbox);
    To copy to clipboard, switch view to plain text mode 
    this is what i need

Similar Threads

  1. Custom button
    By Erik-Moscow in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 16:58
  2. Custom Button
    By wirasto in forum Newbie
    Replies: 1
    Last Post: 14th November 2009, 10:59
  3. Custom widget: a button within a button
    By Gnurou in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 09:03
  4. close button for tabwidget
    By sepehr in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2009, 13:57
  5. How to create a custom Button?
    By Mister_Crac in forum Qt Programming
    Replies: 18
    Last Post: 22nd October 2006, 23:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.