Solved Offsetting the tab in QTabWidget
-
I'm trying to use a QTabWidget to create a simple ribbon style bar.
As creating the QTabWidget where the tabs are on the top, the tabs always start from the left, like this:
What should I do as I want to shift the tabs to the right, to get something like this:
As also how to add a button to the space created by the right-shift? Ultimately I'd like to get something similar to word, like this:
Thanks!
-
Hi,
Not a direct answer however, did you saw QTitanRibbon ?
-
Yes, I did. But I can't afford it... I just need something simple and I think I manage to implement all functional buttons etc, except having tab shifted and putting a main button there.
-
@Pauly
Hi for a "poor man's" version ;)
you can use a stylesheet withQTabWidget::tab-bar {
left: 50px; /* move to the right */
}It might be difficult to use in layout though as the round menu is half in over the tab
but you might be able to tweak to work ok. -
I still have to learn about stylesheet... So where do I set this? Thanks.
QTabWidget::tab-bar {
left: 50px; /* move to the right */
} -
myTabWidget->setStyleSheet("content of my cool style sheet");
-
@Pauly
For start just use Creator
Open a form UI file and place a tabwidget
Then right click it and select Change Stylesheet.
Its a mini editor.And then read
http://doc.qt.io/qt-5/stylesheet-syntax.html -
Thanks a lot. I'm able to get something like this... poor man version...
I think some of the pushbutton at the top left corner is behind the title bar. How can I deal with this? Thanks!
-
@Pauly
Hi
Just set y of the button to zero
Seems to be minus currently. -
To raise the button over the other widgets, use
PushButton->raise();
seems obvious, right.
;-)
-
Yes, I made its y negative trying to have the button sit on top of the title bar, as the word scheme looks like. PushButton->raise(); does not raise it above the title bar. I read some post which said that title bar will always on top? Thanks...
-
@Pauly
The title bar is a so called decoration and is drawn by the OS/windows manager.
So the button can never be on top of it. ( also since its a child of mainwindow )Also the button. is in a layout or anything else ?
-
After some researching, I hide the title bar by adding
setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
Now I get:
Gone with the title bar is the drag&move, the minimize/maximize/close buttons. I guess I can add some widget for those function. Is there a Qt class that handle these kind of actions (title bar actions)? Thanks!
-
@Pauly
Hi
Sadly no, if you remove the decorations, you must re-implement all these features.
That said, if you ONLY need the min/max functions and not resize then its
just a few functions from QMainwindow to mimic those. -
I tried it and it is more invloving to redo the title bar with a widget. The title bar response to upside resize and width change etc. I decide to defer it to later time. Maybe that is not a good idea for poor man. :)
-
@Pauly
Nah for a fully functional version of a "word look" the amount of work would
sort of disqualify it for a poors mans version. :) -
Thanks a lot. :)