Qt-interest Archive, January 2008
Table with fixed/stretched columns
Message 1 in thread
Hi all,
I'm trying to create a table with all except one columns are of fixed size and
one stretchable column occupying the remaining space. Seems easy at a first
view:
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStringList columnLabels;
columnLabels << "C1" << "C2" << "C3" << "C4" << "C5";
QTableWidget *tbl = new QTableWidget(10, columnLabels.size());
tbl->resize(500,500);
tbl->setHorizontalHeaderLabels(columnLabels);
for (int i=0; i<columnLabels.size(); i++)
if (i != 1){
tbl->setColumnWidth(i,50);
tbl->horizontalHeader()->setResizeMode(i,QHeaderView::Fixed);
}
else
tbl->horizontalHeader()->setResizeMode(1,QHeaderView::Stretch);
tbl->show();
return app.exec();
}
But this doesn't work. Only the first column is of size 50, all other columns
are much wider. What am I doing wrong here?
Thanks for your help
Mathias
--
[ signature omitted ]
Message 2 in thread
Are you using qt4.3.3? If so, this will be relevant:
http://lists.trolltech.com/qt-interest/2008-01/msg00315.html#msg00315
Cheers,
Peter
> -----Ursprüngliche Nachricht-----
> Von: Mathias Waack [mailto:Mathias.Waack@xxxxxxxxxx]
> Gesendet: Donnerstag, 17. Januar 2008 13:20
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: Table with fixed/stretched columns
>
> Hi all,
>
> I'm trying to create a table with all except one columns are
> of fixed size and
> one stretchable column occupying the remaining space. Seems
> easy at a first
> view:
>
> #include <QtGui>
>
> int main(int argc, char *argv[])
> {
> QApplication app(argc, argv);
>
> QStringList columnLabels;
> columnLabels << "C1" << "C2" << "C3" << "C4" << "C5";
>
> QTableWidget *tbl = new QTableWidget(10, columnLabels.size());
> tbl->resize(500,500);
> tbl->setHorizontalHeaderLabels(columnLabels);
> for (int i=0; i<columnLabels.size(); i++)
> if (i != 1){
> tbl->setColumnWidth(i,50);
> tbl->horizontalHeader()->setResizeMode(i,QHeaderView::Fixed);
> }
> else
>
> tbl->horizontalHeader()->setResizeMode(1,QHeaderView::Stretch);
>
> tbl->show();
> return app.exec();
> }
>
> But this doesn't work. Only the first column is of size 50,
> all other columns
> are much wider. What am I doing wrong here?
>
> Thanks for your help
>
> Mathias
--
[ signature omitted ]
Message 3 in thread
Hi Peter,
On Thursday 17 January 2008, Peter Prade wrote:
> Are you using qt4.3.3?
yes rigth, I've forgot to mention.
> If so, this will be relevant:
> http://lists.trolltech.com/qt-interest/2008-01/msg00315.html#msg00315
Exactly. Dunno why I haven't found this. Thank you!
Mathias
--
[ signature omitted ]
Message 4 in thread
Hello All
I am using a dll which have a function which takes char * as input for the
path of the file (With out the file name ) and char * for a file name.
As i am using QT 4.3.1. I used QFileDialog so as to allow user to select
the file from the window.
It is explained by code below.
QFileDialog *fileSelect = new QFileDialog(0,"Choose file for importing
",path);
fileSelect->setFileMode(QFileDialog::ExistingFiles);
if(fileSelect->exec() != QDialog::Accepted)return;
QStringList fileNames = fileSelect->selectedFiles();
QString fileName = fileNames.first();
if(fileName.isEmpty()) return;
QFileInfo filePath = fileName;
*************************************
After this i tried some ways to get the File name and path but
with out success.
I am converting the QString to Char * by :-
e.g
QString fileName;
char *s = (fileName.toAscii()).data(); // It works for some other function...
************************************
If i directly provide values to the path char * and file name char * in
the API
function, i have to give the path like
char * path = "D:\\QTProjects\\Sample\\project";
Please help, how to get the file name and path from the QFileDialog.
and path format issue like "D:\\QTProjects\\Sample\\project";
???
Thanks alot...
--
[ signature omitted ]
Message 5 in thread
rohitj wrote:
> QString fileName;
> char *s = (fileName.toAscii()).data(); // It works for some
This is a very common (C++) mistake and has been answered on this list
many times.
try this instead:
QString fileName;
QByteArray byteArray = fileName.toAscii();
char *s = byteArray.data();
this way, the bytearray won't go out of scope, and won't be freed before
you access it.
of course you can get away with something like this:
printf((fileName.toAscii()).data());
this is because the temporary QByteArray isn't freed before printf has
been called. it's freed at the end of the block, indicated by the ;
Cheers,
Peter
--
[ signature omitted ]
Message 6 in thread
Thanks alor Peter........
Now it is working...:-))
Thanks 1000.......
> rohitj wrote:
>> QString fileName;
>> char *s = (fileName.toAscii()).data(); // It works for some
>
> This is a very common (C++) mistake and has been answered on this list
> many times.
>
> try this instead:
>
> QString fileName;
> QByteArray byteArray = fileName.toAscii();
> char *s = byteArray.data();
>
> this way, the bytearray won't go out of scope, and won't be freed before
> you access it.
>
> of course you can get away with something like this:
> printf((fileName.toAscii()).data());
>
> this is because the temporary QByteArray isn't freed before printf has
> been called. it's freed at the end of the block, indicated by the ;
>
> Cheers,
> Peter
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]