Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How modify the Q3DBars with multiple color bars?
Qt 6.12 LTS is out! See what's new in the release blog

How modify the Q3DBars with multiple color bars?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 865 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    f.lerdino
    wrote on last edited by
    #1

    I want to modify the "bars" in the QT example because I need that the bars are set with differents colors.
    Any idea How to do that?

    R 1 Reply Last reply
    1
    • F f.lerdino

      I want to modify the "bars" in the QT example because I need that the bars are set with differents colors.
      Any idea How to do that?

      R Offline
      R Offline
      RainyTown
      wrote on last edited by
      #2

      @f-lerdino 44312478-7847-43f3-96fd-67b1399d37e7-Color3DBarsByHeightExample.png
      Is that what you mean?
      I also want to know how this is achieved.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RainyTown
        wrote on last edited by
        #3

        @f-lerdino if you want something like this:
        3a7ec447-f71b-40e9-ad3f-ec485122db08-image.png
        there is code:

        QGuiApplication app (argc, argv);
        
        	Q3DBars bars;
        	bars.resize (800, 800);
        
        	// Remove the frame for a borderless window
        	bars.setFlags (bars.flags () ^ Qt::FramelessWindowHint);
        
        	bars.rowAxis ()->setRange (0, 4);
        	bars.columnAxis ()->setRange (0, 4);
        
        	QBar3DSeries* series = new QBar3DSeries;
        
        	// Set the color style for the series to ColorStyleRangeGradient
        	series->setColorStyle (Q3DTheme::ColorStyleRangeGradient);
        
        	// Define colors for the color style range gradient
        	QLinearGradient gradient;
        	gradient.setColorAt (0.0, Qt::green);
        	gradient.setColorAt (0.5, Qt::yellow);
        	gradient.setColorAt (1.0, Qt::red);
        
        	// Create a data proxy for the series
        	QBarDataProxy* dataProxy = new QBarDataProxy;
        
        	// Create data items with values
        	QBarDataRow* dataRow = new QBarDataRow;
        	for (int i = 0; i < 5; ++i) {
        		dataRow->append (QBarDataItem (1.0f * 0.1 * i));
        	}
        
        	// Assign color style range gradient to the data proxy
        	//dataProxy->setColorStyle (gradient);
        
        	// Add data row to the data proxy
        	dataProxy->addRow (dataRow);
        
        	// Set data proxy for the series
        	series->setDataProxy (dataProxy);
        	series->setBaseGradient (gradient);
        	bars.addSeries (series);
        	bars.show ();
        
        	return app.exec ();
        }
        

        the key is "series->setColorStyle (Q3DTheme::ColorStyleRangeGradient);"

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved