Page 2 of 2 FirstFirst 12
Results 21 to 34 of 34

Thread: indexWidget() unexpectedly returns a NULL pointer.

  1. #21
    Join Date
    Nov 2010
    Location
    Houston, Texas, USA
    Posts
    30
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    11

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Evidently I must be doing something weird. Not unusual.

    In the meantime I was tinkering with some code. I had to #if 0 my changes to get back to where I was before the changes. Anyway, I got it back. Here is the code:



    Qt Code:
    1. class ButtonDelegate : public QStyledItemDelegate
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit ButtonDelegate(QObject *parent=0);
    7. ~ButtonDelegate();
    8.  
    9. void paint( QPainter *painter,
    10. const QStyleOptionViewItem &option,
    11. const QModelIndex &index) const;
    12.  
    13. QSize ButtonDelegate::sizeHint( const QStyleOptionViewItem &option,
    14. const QModelIndex &index) const;
    15. void unpolish(QWidget *widget);
    16.  
    17. void polish(QWidget *widget);
    18.  
    19. void paintWidget( QPainter *painter,
    20. const QRect &rect,
    21. const QString &cacheKey,
    22. QWidget *widget ) const;
    23.  
    24. protected:
    25.  
    26. void enterEvent ( QEvent * );
    27. void leaveEvent ( QEvent * );
    28.  
    29. private:
    30.  
    31. mutable QTextDocument document;
    32. QPushButton *button;
    33. QLabel *label;
    34.  
    35. };
    36.  
    37.  
    38. ButtonDelegate::ButtonDelegate(QObject *parent) : QStyledItemDelegate(parent)
    39. {
    40. button = new QPushButton( "Wild!");
    41. button->setFixedWidth( 50); // I'm setting this in pixels. There has to be a better way.
    42.  
    43. QPalette pal = button->palette();
    44. pal.setColor(QPalette::ButtonText, QColor(255, 0, 0));
    45. pal.setColor(QPalette::Button, QColor(255, 255, 0));
    46. button->setPalette(pal);
    47. #if 1
    48. label = new QLabel;
    49. label->setTextFormat(Qt::RichText);
    50. label->setWordWrap(false);
    51. #endif
    52. }
    53.  
    54. ButtonDelegate::~ButtonDelegate()
    55. {
    56. delete button;
    57. delete label;
    58. }
    59.  
    60.  
    61. void ButtonDelegate::paint( QPainter *painter,
    62. const QStyleOptionViewItem &option,
    63. const QModelIndex &index) const
    64. {
    65. bool selected = option.state & QStyle::State_Selected;
    66. int yOffset = button->height() < option.rect.height()
    67. ? (option.rect.height() - button->height()) / 2 : 0;
    68.  
    69.  
    70. QRect labelRect(option.rect.x(),
    71. option.rect.y() + yOffset,
    72. option.rect.width() - button->width(),
    73. option.rect.height());
    74.  
    75. QRect buttonRect( option.rect.x() + labelRect.width(),
    76. option.rect.y(),
    77. option.rect.width() - labelRect.width(),
    78. option.rect.height());
    79.  
    80. label->setFixedSize(qMax(0, labelRect.width()),
    81. labelRect.height());
    82.  
    83. QString html = index.model()->data(index, Qt::DisplayRole).toString();
    84.  
    85. label->setText(html);
    86.  
    87. QString buttonKey("PUSHBUTTON");
    88. paintWidget(painter, buttonRect, buttonKey, button);
    89.  
    90. QString labelKey = QString("LABEL:%1.%2.%3x%4").arg(selected)
    91. .arg(html)
    92. .arg(labelRect.width())
    93. .arg(labelRect.height());
    94. paintWidget(painter, labelRect, labelKey, label);
    95. }
    96.  
    97.  
    98.  
    99. void ButtonDelegate::paintWidget( QPainter *painter,
    100. const QRect &rect,
    101. const QString &cacheKey,
    102. QWidget *widget ) const
    103. {
    104. QPixmap pixmap(widget->size());
    105.  
    106. if (!QPixmapCache::find(cacheKey, &pixmap))
    107. {
    108. widget->render(&pixmap);
    109. QPixmapCache::insert(cacheKey, pixmap);
    110. }
    111.  
    112. painter->drawPixmap(rect, pixmap);
    113. }
    114.  
    115.  
    116.  
    117. void HistoryWindow::createModelAndView()
    118. {
    119. setupModel();
    120. ui->treeView->setItemDelegateForColumn(0, new ButtonDelegate);
    121. ui->treeView->setAllColumnsShowFocus(true);
    122. ui->treeView->setModel(model);
    123. SetMouseTransitSignals(this);
    124. for ( int i = 0; i < model->rowCount(); ++i )
    125. {
    126. ui->treeView->openPersistentEditor( model->index(i, 0, QModelIndex()) );
    127. }
    128.  
    129. }
    To copy to clipboard, switch view to plain text mode 


    The openPersistentEditor() is something I added since your last post. This is something that I want to discuss afterward.

    Also, the buttons I had in each delegate vanished. I don't what I missed when I was restoring the code. But you were interested in the labels not the buttons so I didn't pursue it.

    In any case, this code assigns a delegate to the cells in column zero. The model is populated with unique data in every element and that causes the delegates to each have unique data.

    I don't know if this is responsive to your interest in how I accomplished this. Is there something else you would like to see?


    Added after 8 minutes:


    Oh, I overlooked your question
    What if you also comment out existance of the paint() reimplementation in your delegate or call the base class implementation?
    I commented out paint() and it had no effect. I was surprised.


    Added after 4 minutes:


    Update: calling QStyledItemDelegate:aint() from within ButtonDelegate:aint()--and doing nothing else--had no effect.


    Added after 46 minutes:


    Let me change the subject a little. Using openPersistentEditor() I found I could cause another way to make the button appear. Now I needed some way to cause all buttons to disappear except for the button in the mouse's current row.

    currently the createModelAndView() function is called from the HistoryWindow's constructor. It causes a button to appear in column zero for every row.

    Qt Code:
    1. void HistoryWindow::createModelAndView()
    2. {
    3. setupModel();
    4. ui->treeView->setItemDelegateForColumn(0, new ButtonDelegate);
    5. ui->treeView->setAllColumnsShowFocus(true);
    6. ui->treeView->setModel(model);
    7. SetMouseTransitSignals(this);
    8.  
    9. for ( int i = 0; i < model->rowCount(); ++i )
    10. {
    11. ui->treeView->openPersistentEditor( model->index(i, 0, QModelIndex()) );
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    I would have thought the following code would have caused a button to appear in on only the row where the mouse is hovering. It doesn't work as I expected. closePersistentEditor(), which is called from within a 'for loop', does a fine job of making all buttons disappear but, for some reason the following call to openPersistentEditor() unexpectedly fails to cause any buttons to reappear. Why would the call to openPersistentEditor() not have an effect?


    Qt Code:
    1. void HistoryTreeView::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. QAbstractItemModel *m(model());
    4.  
    5. // Only do something when a model is set.
    6. if (m)
    7. {
    8. QModelIndex index = this->indexAt(event->pos());
    9. if (index.isValid())
    10. {
    11.  
    12. // if the mouse has moved to another row
    13. if (index.row() != m_currentRow)
    14. {
    15. m_currentRow = index.row();
    16.  
    17. // clear buttons from all rows
    18.  
    19. for ( int i = 0; i < m->rowCount(); ++i )
    20. {
    21. this->closePersistentEditor( m->index(i, 0, QModelIndex()) );
    22. }
    23.  
    24. // create button in mouse's current row
    25. this->openPersistentEditor(m->index(m_currentRow, 0, index ));
    26. }
    27. }
    28. else // model is invalid
    29. {
    30. m_currentRow = -1;
    31. }
    32. }
    33.  
    34. QTreeView::mouseMoveEvent(event);
    35. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ajax; 30th November 2010 at 22:18. Reason: reformatted to look better

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Your code doesn't make much sense, your label is not even visible! Try calling show() on it and you'll see where it appears. I suggest you take a look at examples bundled with Qt that provide a custom delegate. You'll see how a delegate should be implemented. But again, in my opinion you can scrap your whole delegate because it does nothing useful, I don't know who suggested you it should be implemented this way. All you need is a floating button in the view and place it in the right position as required.


    Added after 13 minutes:


    Here is a quick example of what I mean regarding what you could do:

    Qt Code:
    1. #include <QtGui>
    2.  
    3.  
    4. class View : public QTableView {
    5. Q_OBJECT
    6. public:
    7. View(QWidget *parent = 0) : QTableView(parent) {
    8. viewport()->installEventFilter(this);
    9. viewport()->setMouseTracking(true);
    10. buttonRow = -1;
    11. button = new QPushButton("Click me", viewport());
    12. button->hide();
    13. connect(button, SIGNAL(clicked()), this, SLOT(_q_buttonClicked()));
    14. }
    15. protected:
    16. bool eventFilter(QObject *o, QEvent *e){
    17. if(o==viewport()){
    18. if(e->type() == QEvent::MouseMove){
    19. if(!ev->buttons()) {
    20. QModelIndex idx = indexAt(ev->pos());
    21. if(idx.isValid()){
    22. buttonRow = idx.row();
    23. QRect r = visualRect(idx);
    24. button->show();
    25. button->setGeometry(r.right()+2, r.top(), button->sizeHint().width(), r.height());
    26. } else {
    27. button->hide();
    28. buttonRow = -1;
    29. }
    30. return true;
    31. }
    32. }
    33. }
    34. return QTableView::eventFilter(o, e);
    35. }
    36. private slots:
    37. void _q_buttonClicked() {
    38. QMessageBox::information(this, "click", QString("Clicked on row %1").arg(buttonRow+1));
    39. }
    40. private:
    41. QPushButton *button;
    42. int buttonRow;
    43. };
    44.  
    45. #include "main.moc"
    46.  
    47. int main(int argc, char **argv){
    48. QApplication app(argc, argv);
    49. model.setStringList(QStringList() << "abc" << "def" << "ghi" << "jkl" << "mno" << "pqr" << "stu" << "vwx");
    50. View view;
    51. view.setModel(&model);
    52. view.show();
    53. return app.exec();
    54. }
    To copy to clipboard, switch view to plain text mode 

    As you can see, no custom delegate and items still get painted (without any labels).
    Last edited by wysota; 30th November 2010 at 22:57.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #23
    Join Date
    Nov 2010
    Location
    Houston, Texas, USA
    Posts
    30
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    11

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    your label is not even visible
    But I see the label text! It is visible!

    Regarding why I'm using a delegate: nobody suggested it to me. Our company just started with Qt for the first time a couple of weeks ago. There is nobody else where with any more experience here than I have.

    I arrived at the idea for using a delegate because the spec essentially calls for a button in the same cell as some text, where said cell is in in column zero of a table. I didn't see anything standard that supported that requirement. I read a recommendation in the book C++ GUI Programming with Qt 4 that stated I could have better control over the rendering of items if I used a delegate. After examining some examples I conclude that a delegate would do the job. Of course there is more than one way to do most things, but since I am a newbie I couldn't see another way to get it done.

    Changing the subject back to the question I asked regarding openPersistentEditor(), do you have an idea why it cannot make the button reappear?

    Put another way, I believe that I should be able to make a given button to repeatedly appear and disappear by calling openPersistentEditor() and closePersistentEditor(). Am I wrong?

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Quote Originally Posted by ajax View Post
    But I see the label text! It is visible!
    No, you see the text, not the label text. As an experiment you can change the background or font of the label and see if it is reflected in all your items.

    Edit: Actually it will be because you are then rendering the label to a pixmap and rendering the pixmap to the item which should already make you suspicious that the label part is not needed here as you can paint the text directly.

    Regarding why I'm using a delegate: nobody suggested it to me. Our company just started with Qt for the first time a couple of weeks ago. There is nobody else where with any more experience here than I have.
    So you came up with the polish() and unpolish() methods yourself?

    I read a recommendation in the book C++ GUI Programming with Qt 4 that stated I could have better control over the rendering of items if I used a delegate.
    You are not trying to have more control over rendering items. You want to stuff a button in the view.

    Changing the subject back to the question I asked regarding openPersistentEditor(), do you have an idea why it cannot make the button reappear?
    To be honest I didn't read that part of your post. This is not a correct way to go so I didn't bother to read about it.

    Put another way, I believe that I should be able to make a given button to repeatedly appear and disappear by calling openPersistentEditor() and closePersistentEditor(). Am I wrong?
    "It depends on".

    And see the example from my last post.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #25
    Join Date
    Nov 2010
    Location
    Houston, Texas, USA
    Posts
    30
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    11

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    But I see the label text! It is visible!
    No, you see the text, not the label text. As an experiment you can change the background or font of the label and see if it is reflected in all your items.
    You're correct. I was wrong. I commented out the label stuff from the code and the text was still there. So the label was not containing the text.
    Regarding why I'm using a delegate: nobody suggested it to me. Our company just started with Qt for the first time a couple of weeks ago. There is nobody else where with any more experience here than I have.
    So you came up with the polish() and unpolish() methods yourself?
    Yes. I found them in the book C++ GUI Programming with Qt 4, around pp. 458. They seemed like they might be what I wanted. These methods are leftover from earlier experimentation. At this point I doubt that they are what I need.

    But I see the label text! It is visible!
    No, you see the text, not the label text. As an experiment you can change the background or font of the label and see if it is reflected in all your items.
    You're correct. I was wrong. I commented out the label stuff from the code and the text was still there. So the label was not containing the text.
    Regarding why I'm using a delegate: nobody suggested it to me. Our company just started with Qt for the first time a couple of weeks ago. There is nobody else where with any more experience here than I have.
    So you came up with the polish() and unpolish() methods yourself?
    Yes. I found them in the book C++ GUI Programming with Qt 4, around pp. 458. They seemed like they might be what I wanted. These methods are leftover from earlier experimentation. At this point I doubt that they are what I need.


    Added after 32 minutes:


    OK: now I have the button appearing and disappearing as I need them to do. Not sure what I did but I made sure to commit the code while it is still working.

    Also, wysota, thank you for your patience.

    Now I need to cause the button to float against the right border of its cell. My initial unsuccessful attempt was:

    Qt Code:
    1. void ButtonDelegate::setEditorData( QWidget * editor ,
    2. const QModelIndex & /* index */) const
    3. {
    4. editor->setMaximumWidth( 50 ); // this worked
    5. editor->move(-50,0); // this had no apparent effect
    6. }
    To copy to clipboard, switch view to plain text mode 

    My next unsuccessful attempt was:

    Qt Code:
    1. void ButtonDelegate::setEditorData( QWidget * editor ,
    2. const QModelIndex & /* index */) const
    3. {
    4. editor->setMaximumWidth( 50 ); // this worked
    5. editor->setStyleSheet("float:right;"); // this had no apparent effect
    6. }
    To copy to clipboard, switch view to plain text mode 

    What do you recommend?
    Last edited by ajax; 1st December 2010 at 00:58.

  6. #26
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Quote Originally Posted by ajax View Post
    Yes. I found them in the book C++ GUI Programming with Qt 4, around pp. 458.
    So you didn't come up with it yourself but rather the authors of the book suggested it.

    What do you recommend?
    How did you implement the button?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #27
    Join Date
    Nov 2010
    Location
    Houston, Texas, USA
    Posts
    30
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    11

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Yes. I found them in the book C++ GUI Programming with Qt 4, around pp. 458.
    So you didn't come up with it yourself but rather the authors of the book suggested it.
    Well the authors described how to solve various scenarios using Qt. Nothing I have found, in that book or elsewhere on the Internet, exactly matches what I am attempting to do. Also, while I have years of programming experience (e.g., embedded, databases, telephony, and so on) I have little GUI programming experience and no prior Qt experience.

    So I see myself as parachuting into unfamiliar terrain and casting around for anything that appears to fit the problem I am trying to solve. The risk, of course, is that the stuff I notice might be a much poorer solution than other things that I just haven't yet found. Consequently, I could naively select an inappropriate approach just because I found the inappropriate approach before I happened on a much more suitable one.

    The polish()/unpolish() stuff is an example of something that seemed to me at one time to be a possible part of the solution. Later abandoned that idea but I didn't delete the code. (Hey, who knows, it might be useful later!) By the time you asked about the polish()/unpolish() stuff I'd practically forgotten about it

    Yes. I found them in the book C++ GUI Programming with Qt 4, around pp. 458.
    So you didn't come up with it yourself but rather the authors of the book suggested it.
    Well the authors described how to solve various scenarios using Qt. Nothing I have found, in that book or elsewhere on the Internet, exactly matches what I am attempting to do. Also, while I have years of programming experience (e.g., embedded, databases, telephony, and so on) I have little GUI programming experience and no prior Qt experience.

    So I see myself as parachuting into unfamiliar terrain and casting around for anything that appears to fit the problem I am trying to solve. The risk, of course, is that the stuff I notice might be a much poorer solution than other things that I just haven't yet found. Consequently, I could naively select an inappropriate approach just because I found the inappropriate approach before I happened on a much more suitable one.

    The polish()/unpolish() stuff is an example of something that seemed to me at one time to be a possible part of the solution. Later abandoned that idea but I didn't delete the code. (Hey, who knows, it might be useful later!) By the time you asked about the polish()/unpolish() stuff I'd practically forgotten about it


    Added after 12 minutes:


    How did you implement the button?

    Qt Code:
    1. QWidget * ButtonDelegate::createEditor( QWidget * parent,
    2. const QStyleOptionViewItem & option,
    3. const QModelIndex & index ) const
    4. {
    5. if (index.column() == 0 )
    6. {
    7. return new QPushButton("Share", parent);
    8. }
    9. else
    10. {
    11. return QStyledItemDelegate::createEditor(parent, option, index );
    12. }
    13. }
    14.  
    15. void ButtonDelegate::setEditorData( QWidget * editor ,
    16. const QModelIndex & /* index */) const
    17. {
    18. editor->setMaximumWidth( 50 ); // in px
    19. editor->setStyleSheet("float:right;"); // didn't affect button location
    20. //editor->move(-50,0); // this didn't work either
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ajax; 1st December 2010 at 15:14.

  8. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    So you have to click the cell for the button to appear and at the same time the content of the cell disappears. Is that really what you wanted?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #29
    Join Date
    Nov 2010
    Location
    Houston, Texas, USA
    Posts
    30
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    11

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    So you have to click the cell for the button to appear and at the same time the content of the cell disappears. Is that really what you wanted?
    Uh, no that is not what I desire. The spec requires:
    1. that the button normally be invisible
    2. That the button be visible so long as the mouse is hovering somewhere over the same row where the button resides
    3. and that the button vanish after the mouse departs from the button's row


    As of this writing I am happy to say that the buttons are exhibiting this exact behavior. My current issue is that the button is located on the left edge of the cell. I desire to make it right-aligned. I found a Qt::AlignRight enum that would seem to specify the desired button location but I cannot figure out how to use it.

    Anyway, getting back to the behavior the button is to show when it is pressed: The button is to pop a context sensitive dialog when the user clicks it. The exact text displayed in the pop-up dialog will be determined by the data contained within the clicked button's row.

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Ok, if you want to go this way I will not stop you although this all implicitly makes the column of your model that the view displays the buttons in read-only and is in general the wrong approach. So that you know...

    Quote Originally Posted by ajax View Post
    My current issue is that the button is located on the left edge of the cell.
    Reimplement QAbstractItemDelegate::updateEditorGeometry().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #31
    Join Date
    Nov 2010
    Location
    Houston, Texas, USA
    Posts
    30
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    11

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Qt Code:
    1. Reimplement QAbstractItemDelegate::updateEditorGeometry().
    To copy to clipboard, switch view to plain text mode 

    OK, I have googled around quite a bit and it appears that I need to do something like:

    Qt Code:
    1. QStyleOptionViewItem opt = viewOptions();
    2. opt.decorationAlignment = Qt::AlignRight;
    To copy to clipboard, switch view to plain text mode 

    My problem is that I cannot figure out how to do something like this from within the context of updateEditorGeometry().

    How would I approach this?

  12. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Quote Originally Posted by ajax View Post
    OK, I have googled around quite a bit and it appears that I need to do something like:

    Qt Code:
    1. QStyleOptionViewItem opt = viewOptions();
    2. opt.decorationAlignment = Qt::AlignRight;
    To copy to clipboard, switch view to plain text mode 
    No, not really. Just call setGeometry on the widget with the parameters you want based on the rectangle provided by the style option.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    ajax (2nd December 2010)

  14. #33
    Join Date
    Nov 2010
    Location
    Houston, Texas, USA
    Posts
    30
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    11

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Thanks wysota!

    as a public service to the other newbies, here is what I did:
    Qt Code:
    1. void ButtonDelegate::updateEditorGeometry( QWidget *editor,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index ) const
    4. {
    5. QStyleOptionViewItem opt( option );
    6.  
    7. //subtract the width of the button from the width of its containing cell
    8. const int x = opt.rect.width() - SELECT_BUTTON_WIDTH;
    9.  
    10. // right align the button in the cell
    11. opt.rect.setX( x );
    12. editor->setGeometry(opt.rect);
    13. }
    To copy to clipboard, switch view to plain text mode 

  15. #34
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: indexWidget() unexpectedly returns a NULL pointer.

    Also as a public service there is a note for all newbies that the functionality desired by the OP should not be implemented this way (with "this way" meaning to use createEditor() and family to place a button or any other widget into a model item with existing data).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Program has unexpectedly finished
    By Maluko_Da_Tola in forum Newbie
    Replies: 5
    Last Post: 1st December 2010, 09:54
  2. Application stops working unexpectedly
    By baluk in forum Newbie
    Replies: 16
    Last Post: 20th November 2010, 15:06
  3. Replies: 1
    Last Post: 28th June 2010, 06:21
  4. QDBusMessage returns NULL string
    By nrabara in forum Qt Programming
    Replies: 0
    Last Post: 27th November 2009, 06:09
  5. Dereferencing a NULL Pointer for staticMetaObject?
    By hyling in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 00:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.