Results 1 to 7 of 7

Thread: QStyleOptionProgressBar doesn't display right in OSX

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QStyleOptionProgressBar doesn't display right in OSX

    Hi,

    Anyone has tied this style in a Mac? The bar is always disabled and no text appears

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QStyleOptionProgressBar doesn't display right in OSX

    Does a plain QProgressBar work ok? Maybe an important setting was forgotten from the style option? See QProgressBar sources for reference how to fill it properly?
    J-P Nurmi

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

    Default Re: QStyleOptionProgressBar doesn't display right in OSX

    What style? QStyleOptionProgressBar is a little class that holds information about the parameters of an element that is to be drawn. If you want to use it, you have to fill this object with parameters.

  4. #4
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStyleOptionProgressBar doesn't display right in OSX

    Sorry the question was drawing a progress bar delegate in OSX, like the Qt Torrent example one (that fails too).

    ATM I have solved it using a QPlastiqueStyle that's multiplatform.

    Thank's

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QStyleOptionProgressBar doesn't display right in OSX

    But does a plain QProgressBar get drawn ok? I mean the widget, not custom drawing.
    J-P Nurmi

  6. #6
    Join Date
    Apr 2007
    Location
    United States
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Post Re: QStyleOptionProgressBar doesn't display right in OSX

    an example of something you would use in the paint method of your delegate would be this:

    Qt Code:
    1. QStyleOptionProgressBarV2 progressOptions;
    2.  
    3. progressOptions.rect = option.rect;
    4. progressOptions.minimum = 0;
    5. progressOptions.maximum = 100;
    6. progressOptions.progress = 50;
    7. progressOPtions.text = QString("%1%").arg(50);
    8. progressOptions.textVisible = true;
    9.  
    10. QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressOptions, painter, 0);
    To copy to clipboard, switch view to plain text mode 

    Where all of the values you would pull out of your model instead of hard coding them like i did in this example. The last line (setting textVisible to true) is what tells it to display text. If you don't set that to true it will only draw the physical progress bar without any text. I hope that helps you out.

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QStyleOptionProgressBar doesn't display right in OSX

    The torrent example does set the text visible. This is how the example fills the style option:
    Qt Code:
    1. // Set up a QStyleOptionProgressBar to precisely mimic the
    2. // environment of a progress bar.
    3. QStyleOptionProgressBar progressBarOption;
    4. progressBarOption.state = QStyle::State_Enabled;
    5. progressBarOption.direction = QApplication::layoutDirection();
    6. progressBarOption.rect = option.rect;
    7. progressBarOption.fontMetrics = QApplication::fontMetrics();
    8. progressBarOption.minimum = 0;
    9. progressBarOption.maximum = 100;
    10. progressBarOption.textAlignment = Qt::AlignCenter;
    11. progressBarOption.textVisible = true;
    12.  
    13. // Set the progress and text values of the style option.
    14. int progress = qobject_cast<MainWindow *>(parent())->clientForRow(index.row())->progress();
    15. progressBarOption.progress = progress < 0 ? 0 : progress;
    16. progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
    17.  
    18. // Draw the progress bar onto the view.
    19. QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
    To copy to clipboard, switch view to plain text mode 
    It's interesting that the snippet above doesn't work in Mac. I would be really interested to hear whether an ordinary QProgressBar widget works as expected. QProgressBar fills the style option like this:
    Qt Code:
    1. void QProgressBar::initStyleOption(QStyleOptionProgressBar *option) const
    2. {
    3. if (!option)
    4. return;
    5. Q_D(const QProgressBar);
    6. option->initFrom(this);
    7.  
    8. if (d->orientation == Qt::Horizontal)
    9. option->state |= QStyle::State_Horizontal;
    10. option->minimum = d->minimum;
    11. option->maximum = d->maximum;
    12. option->progress = d->value;
    13. option->textAlignment = d->alignment;
    14. option->textVisible = d->textVisible;
    15. option->text = text();
    16.  
    17. = qstyleoption_cast<QStyleOptionProgressBarV2 *>(option)) {
    18. optionV2->orientation = d->orientation; // ### Qt 5: use State_Horizontal instead
    19. optionV2->invertedAppearance = d->invertedAppearance;
    20. optionV2->bottomToTop = (d->textDirection == QProgressBar::BottomToTop);
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 
    As you can see, the only remarkable difference is QStyleOption::initFrom() which initializes the state, direction, rect, palette, and fontMetrics. I can see from QStyleOption::initFrom() sources that some special tricks are done with state when Q_WS_MAC is in question. Maybe it's because of that?
    J-P Nurmi

Similar Threads

  1. Replies: 8
    Last Post: 18th March 2011, 11:27
  2. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 21:55
  3. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  4. Display and divide the image
    By kiransu123 in forum Qt Programming
    Replies: 19
    Last Post: 5th March 2007, 20:40
  5. Modifying the Display on Device
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 13th April 2006, 04:36

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.