PDA

View Full Version : QTabWidget customization



asafzakay
29th April 2008, 01:18
hello everybody
i have a problem with customization of the QTabWidget
i want it to look like this:

i attached a picture
any idea

songqiming
29th April 2008, 02:20
maybe use setTabPosition( TabPosition ) of QTabWidget. TabPosition = QTabWidget::West.
I don't test, you can try.

asafzakay
29th April 2008, 11:54
i'v tried the setTabPosition but i want to change the tab text direction to be vertical to the widget.
thanx anyway

asish_cse
14th September 2010, 07:33
could u solved this problem.I need the same thing into bottom side.can u help me plz ? how to set tabposition?

Lykurg
14th September 2010, 07:46
Hey don't hijack 2 year old post! RTMF or at least read the thread you are writing in. The first answer tells you the solution!

notton
9th November 2010, 03:10
This maybe help you:
http://blog.csdn.net/notton/archive/2010/11/09/5996730.aspx
http://hi.csdn.net/attachment/201011/9/0_12892695378IfX.gif

--------------------------------------------------
--------- Welcome www.thinkvd.com -------
--------------------------------------------------

cdebel2005
28th March 2013, 21:13
Hey don't hijack 2 year old post! RTMF or at least read the thread you are writing in. The first answer tells you the solution!

Wait... seriously, "Guru", "Nokia Certified / Qt Developer"? At least you could follow your own comment "AT LEAST READ THE THREAD YOU ARE WRITING IN".

Setting the TabWidget to WEST won't do what the poster asked for. And he already wrote it in the 3rd msg of this thread.

I'm reading threads and it's full of little bastard saying "Read the f... manual".

Maybe you should tell your mom "Hey bi@tch, you probably did't RTFM about how to raise kids!"

By the way, it's RTFM, not RTMF... at least when you insult people, do it correctly!

Lykurg
29th March 2013, 12:57
Wait... seriously, "Guru", "Nokia Certified / Qt Developer"?
Which came long after that post...

Beside that, you must be really upset if your first post is to tell that (without helping the thread starter in any way). And as you obviously are stressed I was that time, and we both used a post to relieve that pressure. Not the right way, but as you showed with your post, we are not such different ;-)

And I don't know what my mother have to do with it...

ataraxic
14th July 2013, 11:33
Wait... seriously, "Guru", "Nokia Certified / Qt Developer"?

+1 to cdebel2005

I've had this problem (and still do btw) and came across this thread.
Reading answers like "RTFM (ahh... sorry RTMF)" is a waste of everybody's time.
If you do not know the answer -- don't post. You are useless and of no help.

And yes, I've used my first post to tell that... Because I am really upset with the "Guru's" like you.

Lykurg
16th July 2013, 09:36
Go ahead blaming me because of a typo. You also seem to not have understand the relation between tags like "Guru" and time of posting. Beside, I didn't gave me the title "Guru". It is just related on how many post you do here. Even if they are crap. So please do not blame me for things I am not responsible for. But anyway go on, dish the dirt, I do not care.

Or you can start spending the time solving your problem. As I am not very willing to help you after such comment (problem is the language not necessarily the content), but for the sake of peace I give a starting point. You just have to change it for your needs:


class CustomTabStyle : public QProxyStyle
{
public:
QSize sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &size, const QWidget *widget) const
{
QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
if (type == QStyle::CT_TabBarTab)
s.transpose();
return s;
}

void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
if (element == CE_TabBarTabLabel)
{
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option))
{
QStyleOptionTab opt(*tab);
opt.shape = QTabBar::RoundedWest;
QProxyStyle::drawControl(element, &opt, painter, widget);
return;
}
}
QProxyStyle::drawControl(element, option, painter, widget);
}
};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QTabBar tb;
tb.setStyle(new CustomTabStyle);
tb.addTab("Tab 1");
tb.addTab("Tab 2");
tb.show();

return a.exec();
}

To protect me against an other shit storm about how a Guru can write such a code: It is not the most elegant solution - I know -, but it is easy, quick and working.

EDIT: For a good starting point of reading: http://qt-project.org/doc/qt-4.8/style-reference.html (section Tabs)

ataraxic
16th July 2013, 21:38
Go ahead blaming me because of a typo.

Exellent...
That's what I was speaking about. Nice, neat, right to the point, no bullshit.
Thanks for help!

Sorry for the flames before. They were just because there are alot of >/dev/null posts around
that are really annoying.

ataraxic
21st July 2013, 10:55
There is another useful thread related to this question (west qtabwidget with horizontal text):

http://www.qtforum.org/article/28672/how-to-change-qtabwidget-s-tab-positon.html


Go ahead blaming me because of a typo

Hello Lykurg,
After trying your solution as is, I've got the following:

9311

Can you explain pls howto make horizontal text tabs and keep west qtab?

Thank you!

Lykurg
22nd July 2013, 07:08
You only have to change a row and add one:
#include <QtGui>

class CustomTabStyle : public QProxyStyle
{
public:
QSize sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &size, const QWidget *widget) const
{
QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
if (type == QStyle::CT_TabBarTab)
s.transpose();
return s;
}

void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
if (element == CE_TabBarTabLabel)
{
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option))
{
QStyleOptionTab opt(*tab);
opt.shape = QTabBar::RoundedNorth;
QProxyStyle::drawControl(element, &opt, painter, widget);
return;
}
}
QProxyStyle::drawControl(element, option, painter, widget);
}
};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QTabBar tb;
tb.setStyle(new CustomTabStyle);
tb.setShape(QTabBar::RoundedWest);
tb.addTab("Tab 1");
tb.addTab("Tab 2");
tb.show();

return a.exec();
}

gurunbr
26th September 2013, 08:30
Hi Lykurg,

Is this possible I use your solution to rotate tab bar text from vertical to horizontal. if possible means how?. I attached my output as image. see this,9637

ataraxic
6th October 2013, 20:27
Here is a working example of the QTabWidget based on Lykurg CustomTabStyle class.
Works like charm with QT5.0 && QT5.1

tabdialog.pro:


QT += widgets

SOURCES = main.cpp


main.cpp:


#include <QtGui>
#include <QWidget>
#include <QDialog>
#include <QApplication>
#include <QtWidgets>

class CustomTabStyle : public QProxyStyle
{
public:
QSize sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &size, const QWidget *widget) const
{
QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
if (type == QStyle::CT_TabBarTab)
s.transpose();
return s;
}

void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
if (element == CE_TabBarTabLabel)
{
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option))
{
QStyleOptionTab opt(*tab);
opt.shape = QTabBar::RoundedNorth;
QProxyStyle::drawControl(element, &opt, painter, widget);
return;
}
}
QProxyStyle::drawControl(element, option, painter, widget);
}
};

int main(int argc, char *argv[], char *envp[])
{
QApplication app(argc, argv);

QTabWidget *tabWidget = new QTabWidget;

tabWidget->setTabPosition(QTabWidget::West);
tabWidget->tabBar()->setStyle(new CustomTabStyle);

tabWidget->addTab(new QWidget, "General");
tabWidget->addTab(new QWidget, "Permissions");
tabWidget->addTab(new QWidget, "Applications");

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(tabWidget);

tabWidget->show();

return app.exec();
}


to compile (! M$):


qmake -o Makefile tabdialog.pro
make


output:
9673

rawfool
26th February 2014, 11:45
Thanks for this. But I'm having some problems related to size of icon; resizing of tab width, height; setting the color of tab
In tried like this, but I think that's not the proper way to change the size

QSize sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &size, const QWidget *widget) const
{
QSize s = QProxyStyle::sizeFromContents(type, option, QSize(40, 120), widget); // instead of size, I'm hardcoding the value with QSize(40, 120)
if (type == QStyle::CT_TabBarTab)
s.transpose();
return s;
}
1. I'm setting 64x64 pix icon, but still it's being displayed as a small icon. How do I set it to show original size of icon ?
2. How to give custom width & height to the tab ?
3. How to set the color of tab

Kindly help. Thank you.

ckvsoft
26th November 2017, 11:01
Hallo

I know, this is an old Thread but i found it now ;-)

On MAC (Sierra QT5.6) i can't see the Text.
Any ideas?
thx Chris