PDA

View Full Version : Q3ListView expand arrows incorrect on Mac in Qt 4.8



AndyBrice
3rd April 2012, 23:13
The expand/collapse arrows for Q3ListView look wrong on Mac OS X. See attached Windows and Mac screenshots.

7554

7555

In the Mac screenshot the expand/collapse arrows are partly obscured by the Q3ListViewItems. It looks quite wrong. The problem also exists in Qt 4.7, but not in Qt 4.2 (I haven't tried releases in between).

Here is the code to replicate the problem:



#include <QApplication>
#include <Q3ListView>
int
main( int argc, char* argv[] )
{
QApplication app( argc, argv );

Q3ListView w;
w.setRootIsDecorated( true );
w.addColumn( "col1" );
w.show();

Q3ListViewItem* item1 = new Q3ListViewItem( &w, "item1" );
Q3ListViewItem* item2 = new Q3ListViewItem( item1, "item2" );
Q3ListViewItem* item3 = new Q3ListViewItem( item2, "item3" );

QObject::connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );

return app.exec();
}


Surely I can't be the only person using Q3ListView on Mac? I have searched, but can't find an answer. Any ideas?

Lykurg
3rd April 2012, 23:22
Surely I can't be the only person using Q3ListView on Mac?
OT, but I hope you are! Qt5 is coming soon, Qt4 is out for years and you still deal with Qt3? Is that a new application?


On my mac it also looks corrupted. You can try to write a custom delegate to adjust the position.

AndyBrice
3rd April 2012, 23:37
The application is ~7 years old and it still has some Qt3 classes.

Lykurg
3rd April 2012, 23:53
Did I wrote delegate... This adjust the arrow of item 2. Not nice, but a quick workaround.
#include <QApplication>
#include <Q3ListView>
#include <Qt3Support>


class A : public Q3ListViewItem {
public:
A(Q3ListView *parent, const QString &label1) : Q3ListViewItem(parent, label1) {}
void paintBranches(QPainter *p, const QColorGroup &cg, int w, int y, int h) {
Q3ListViewItem::paintBranches(p, cg, w-7, y, h);
}
};


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

Q3ListView w;
w.setRootIsDecorated( true );
w.addColumn( "col1" );
w.show();

A* item1 = new A( &w, "item1" );
Q3ListViewItem* item2 = new Q3ListViewItem( item1, "item2" );
Q3ListViewItem* item3 = new Q3ListViewItem( item2, "item3" );

QObject::connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );

return app.exec();
}

AndyBrice
4th April 2012, 00:23
Lykurg,

A quick workaround is just fine! I tried your solution and it works fine for items with parents. But the root items still look wrong. Do you know where the expand/collapse arrow for the root item get drawn, in Q3ListViewItem::paintCell()?

Added after 5 minutes:

Here you can see the root item still doesn't look correct:

7556


#include <QApplication>
#include <Q3ListView>

class MyListViewItem : public Q3ListViewItem {
public:
MyListViewItem(Q3ListView *parent, const QString &label1) : Q3ListViewItem(parent, label1) {}
MyListViewItem(Q3ListViewItem *parent, const QString &label1) : Q3ListViewItem(parent, label1) {}
void paintBranches(QPainter *p, const QColorGroup &cg, int w, int y, int h) {
Q3ListViewItem::paintBranches(p, cg, w-7, y, h);
}
};

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

Q3ListView w;
w.setRootIsDecorated( true );
w.addColumn( "col" );
w.show();

MyListViewItem* item1 = new MyListViewItem( &w, "item1" );
MyListViewItem* item2 = new MyListViewItem( item1, "item2" );
MyListViewItem* item3 = new MyListViewItem( item2, "item3" );
MyListViewItem* item4 = new MyListViewItem( item3, "item4" );

QObject::connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );

return app.exec();
}

Lykurg
4th April 2012, 06:42
Ahh, it is a private Q3ListViewItem which is hard to reach. So forget all I have said and do it this way (which don't need much changes.):


#include <QtGui>
#include <Q3ListView>

class MyStyle : public QProxyStyle {
public:
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
if (control == QStyle::CC_Q3ListView)
{
QStyleOptionComplex *oo = const_cast<QStyleOptionComplex*>(option);
oo->rect.adjust(0,0,-7,0);
QProxyStyle::drawComplexControl(control, oo, painter, widget);
}
else
QProxyStyle::drawComplexControl(control, option, painter, widget);

}
};

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


Q3ListView w;

MyStyle style;
w.setStyle(&style);

w.setRootIsDecorated( true );
w.addColumn( "col" );
w.show();

Q3ListViewItem* item1 = new Q3ListViewItem( &w, "item1" );
Q3ListViewItem* item2 = new Q3ListViewItem( item1, "item2" );
Q3ListViewItem* item3 = new Q3ListViewItem( item2, "item3" );
Q3ListViewItem* item4 = new Q3ListViewItem( item3, "item4" );

QObject::connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );

return app.exec();
}

AndyBrice
4th April 2012, 10:11
That seems to work perfectly. Much appreciated!

best regards

Andy Brice
http://www.perfecttableplan.com
http://www.successfulsoftware.net