שאלה לשולטים ב-QT

mikledet

New member
שאלה לשולטים ב-QT

מאחר וכתבתי את השאלה במקור לפורום אחר באנגלית, אני פשוט "מדביק" אותה שוב במקום לנסח הכל מחדש - אבל אנגלית לא צריכה להפחיד נכון?
תודה מראש.
Hi, I am tryingt to create a file dialog, that instead of file list, will show in a grid, the content preview of the file - much like it works in Konqueror in "Icon view" (it will show a preview of image files). Where I get confused is with the QGridView. I read the docs, which are rather clear to _what_ to do with QGridView, but not so much (to me) as to how to "connect" it to the rest of my program... Here is what I did, and it doesn't work: I created a dialog, which is the overall filedialog. In it, are the obligatory filename and filter fields, your 'Ok' and 'Cancel button. The file "viewing area" is a QScrollView dervied calss, that has the widget with the QGrdidView (and on it the file labels) added to it as child. Each file "label" is a derived class from QFilePreview (and QLabel). The file dialog will popup, but with no visible files in a grid (tottaly empty). I broke the problem to bits, and the prolem starts, at the QGridView and the widget that holds it (where the file lables are supposed to be). I am adding code below, but I think my problem is conceptual, rather then syntatical. If there is anyone who could explain to me in simple words, and maybe some pseudo code, how to "fuse" a widget and a QGridView - I think this will put me on the right track. If there are any more remarks or sugestions - they will be very welcome. I know you want some code, so here is what I think is relevant to make things clearer - if you need more - just let me know: //The scrollview class DScrollThumb : public QScrollView { Q_OBJECT public: DThumbView *m_thumbView; //this should hold the gridview with the file previews public: DScrollThumb(QWidget *parent=0, const char *name=0); ~DScrollThumb(); }; /////////////////////////////////////////////////////////////////////////////// //This is the FileDialog constuctor, where you can see m_thumbView added to the scrollview DThumbFileView::DThumbFileView(QWidget *parent, const char *name ) : thumbFileView(parent,name) { m_scrollView.m_thumbView = new DThumbView(0,0,m_dir.absPath()); m_scrollView.addChild(m_scrollView.m_thumbView); ////////////////////////////////////////////////////////////////////////////// //The preview label for the files (I think this is ok) class DPreview : public QLabel , public QFilePreview { Q_OBJECT public: public: DPreview( QString fileName="",QWidget *parent=0 ) : QLabel( parent ) { } void previewUrl( const QUrl &u ) { QString path = u.path(); QPixmap pix( path ); if ( pix.isNull() ) setText( u.fileName() ); else setPixmap( pix ); } void previewUrl(QString fileName) { QUrl url; url.setPath(fileName); previewUrl( url ); } ~DPreview(){} }; //////////////////////////////////////////////////////////////////////////// //This is the widget that should hold the gridview with the prview lables - I think the problem is here, or between here and the scrollview... DThumbView::DThumbView(QWidget *parent, const char *name, QString path ) : QWidget(parent) { QGridLayout *gridLayout = new QGridLayout(this); if(path!="") { m_dirPath = path; m_dir.setPath(path); populateView(m_dir.entryList("*.*"),gridLayout); } else { } } Many thanks in advance Dani.​
 

mikledet

New member
תיקון קטן...

בטעות כתבתי QGridView במקום QGridLayout בשאלה. הראשון היה פותר לי כניראה את הבעיה, מאחר שזו מחלקה נגזרת מQWidget שמכילה כבר GridLayout הבעיה איתה - שהי מיועדת לטבלאות עם גודל מוגדר - בעוד שאני זקוק לטבלה דינאמית... אבל מהקוד ניתן לראות את השמוש ב-QGridLayout ולא ב-QGridView.
 
למעלה