[SOLVED] Overlap two widget



  • Hello,

    I would like to create this kind of window.
    I use a QTabWidget customized using StyleSheet so I managed to add a space between the first and the second tabs, Now, I would like to put some QPushButton between those tabs.

    Since the central widget is setup as a vertical layout I don't know how to add three QPushButton that overlap the QTabWidget and that do not stand below the QTabWidget.

    Does anyone know how to perform this ?

    !http://i61.tinypic.com/2ikusew.png!


  • Lifetime Qt Champion

    Hi,

    Just an idea but you could use QTabBar::setTabButton with a custom widget containing your buttons.

    Hope it helps



  • You'll have to position them manually. I'd create a container widget that contains the buttons (and manages them in a horizontal layout or even just use a QToolBar), and give that container the tab widget as its parent (without using a layout to manage its geometry). Then, use an event filter on the tab widget to position the button container in case of resizes and moves.

    It looks like you're trying to re-create some sort of ribbon like UI. If so, you could also consider using DevMachines QTitanRibbon component.



  • [quote author="SGaist" date="1391200102"]Just an idea but you could use QTabBar::setTabButton with a custom widget containing your buttons.
    [/quote]

    I haven't thought about this trick. I'll try it.

    [quote author="Andre" date="1391282276"]You'll have to position them manually. I'd create a container widget that contains the buttons (and manages them in a horizontal layout or even just use a QToolBar), and give that container the tab widget as its parent (without using a layout to manage its geometry). Then, use an event filter on the tab widget to position the button container in case of resizes and moves.[/quote]

    If SGaist's trick doesn't work I'll try yours.

    [quote author="Andre" date="1391282276"]It looks like you're trying to re-create some sort of ribbon like UI. If so, you could also consider using DevMachines QTitanRibbon component. [/quote]

    I'm aware of QTitanRibbon but I'm deveopping a personal project I won't sell, maybe it will be open source so I don't want to spend 500$ in a component. But thanks for the idea.



  • [quote author="SGaist" date="1391200102"]Just an idea but you could use QTabBar::setTabButton with a custom widget containing your buttons.[/quote]

    I've tried your solution, it almost works but it's not perfect.
    I've created a widget container with two QPushButton in it. I've associated it to the second tab and it worked. But now, I would like to set the style for the second tab only so it won't have border but I can't cause using the stylesheet I can define styles for QTabBar::tab::first, QTabBar::tab::middle, QTabBar::tab::last or QTabBar::tab::selected but not the a specific tab.



  • It works.
    Andre's solution is the simplest way to do that.

    Here the code.
    @ui->widget->setParent( ui->tabWidget );
    ui->widget->setGeometry( QRect(64, 0, 84, 28) );@

    The image below shows the result.
    Thanks guys for your help.

    !http://s3.postimg.org/aic0l6gur/Untitled.png!



  • Glad to see its working for you. One small tip: it would be wise to use more descriptive names than "widget" for your objects. That makes your code easier to read back later on. Remember, you'll write code once, but will read it at least about a dozen times later one. Its worth making that reading as easy as possible.



  • [quote author="Andre" date="1391419136"]Glad to see its working for you. One small tip: it would be wise to use more descriptive names than "widget" for your objects. That makes your code easier to read back later on. Remember, you'll write code once, but will read it at least about a dozen times later one. Its worth making that reading as easy as possible.[/quote]

    It's actually what I do in my final project, I name the variables using a prefix such as (int iValue, unsigned short usCounter), here is just a sample app I won't use it in the release version. I never test big tricks in the final project to not insert bugs it if I finally decide to remove the test part.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.